jwarmenhoven / islr-python Goto Github PK
View Code? Open in Web Editor NEWAn Introduction to Statistical Learning (James, Witten, Hastie, Tibshirani, 2013): Python code
License: MIT License
An Introduction to Statistical Learning (James, Witten, Hastie, Tibshirani, 2013): Python code
License: MIT License
Hi, when I exercuted the following snippet within chapter-8 Tree-based Methods.
graph2 = print_tree(clf, features=X2.columns, class_names=['No', 'Yes'])
Image(graph2.create_png())
Ipython gave me some error message
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-15-fc4f6f6b365b> in <module>()
1 graph2 = print_tree(clf, features=X2.columns, class_names=['No', 'Yes'])
----> 2 Image(graph2.create_png())
AttributeError: 'list' object has no attribute 'create_png'
My python enviroment is anaconda python 3.5 + pydot 1.2.3
. Any suggestion to fix this problem? Thanks
I fix it using:
fit3 = sm.GLM(df_steps.wage, df_steps_dummies.drop([df_steps_dummies.columns[1]], axis=1)).fit()
What seems to be the problem with this plot? I think I created the meshgrid correctly, but it does not have the symmetrical shape as the one in the book.
I contacted Trevor Hastie to ask him about the R code for plot on the left. He was so kind to send me the following code. You will need to load the advertising data first and skip the first two lines and the last line.
load("Chapter3.RData")
postscript(file="../Figs/leastsqexample1.ps",width=7,height=7,pointsize=14,horizontal=F)
set.seed(22)
par(mfrow=c(1,1),mar=c(5,5,2,2))
g=50
x=advertising$TV-mean(advertising$TV)
y=advertising$Sales
b=sum((x-mean(x))*(y-mean(y)))/sum((x-mean(x))^2)
a=mean(y)-b*mean(x)
RSS.min=sum((y-as.vector(cbind(1,x)%*%c(a,b)))^2)/100000
a.grid=seq(a-2,a+2,length=g)
b.grid=seq(b-.02,b+.02,length=g)
grid=as.matrix(expand.grid(a.grid,b.grid))
RSS=rep(0,g^2)
for (i in 1:(g^2)){
yhat=as.vector(cbind(1,x)%*%grid[i,])
RSS[i]=sum((y-yhat)^2)/1000
}
RSS=matrix(RSS,g,g)
m=which.min(RSS)
contour(a.grid-b*mean(advertising$TV),b.grid,RSS,xlab=expression(beta[0]),ylab=expression(beta[1]),levels=c(2.11,2.15,2.2,2.3,2.5,3),axes=T,frame.plot=T,col=4,drawlabels=T,cex.lab=1.5,labcex=1.3)
points(a-b*mean(advertising$TV),b,col=2,pch=19,cex=1.5)
dev.off()
X_train = pd.read_csv('Data/Hitters_X_train.csv', index_col=0)
y_train = pd.read_csv('Data/Hitters_y_train.csv', index_col=0)
X_test = pd.read_csv('Data/Hitters_X_test.csv', index_col=0)
y_test = pd.read_csv('Data/Hitters_y_test.csv', index_col=0)
I've also transcribed the Statistical Learning material into Python but only for my own reference. Yours is very elegant and I wish I'd discovered it at the beginning of the course rather than the end.
I noticed that you've gone to the extra step of dumping the R data to file and then loading into the Python environment in Jupyter. In my notes I wanted to have the R and Python code on top of each other for easy reference, so I installed an R virtualenv and built a "bilingual" Jupyter kernel that handles both languages. So far I've had good results using this version of rpy2 with Python 3.5 to invoke R magics in Jupyter and intersperse the two languages in the same notebook.
See my attached notebook, in case you find it useful.
StatLearning_Chapter4R_inPython.ipynb.zip
I moved my local repository to another environment and need to fix the graphviz/pydot setup to be able to create the graphical representation of the decision trees. I accidently pushed an update to GitHub.
Library not loaded: /usr/local/opt/gcc/lib/gcc/9/libgfortran.5.dylib
Reason: image not found
Hi, I clicked the link (http://www-bcf.usc.edu/~gareth/ISL/data.html) in the Chapter 3 Jupyter Notebook but it directed me to (http://faculty.marshall.usc.edu/gareth-james/) and I can't find the data there.
Use sklearn.preprocessing.StandardScaler to scale training set features and apply same transform to the test set.
Hi,
I am trying to run a code same as for chapter 6 provided here:
When I reach the point:
In[7]:
grid = 10**np.linspace(10,-2,100)
ridge3 = gln.ElasticNet(alpha=0, lambda_path=grid)
ridge3.fit(X, y)
I get this error:
AttributeError Traceback (most recent call last)
in ()
1 grid = 10**np.linspace(10,-2,100)
2
----> 3 ridge3 = gln.ElasticNet(alpha=0, lambda_path=grid)
4 ridge3.fit(X, y)
AttributeError: module 'glmnet' has no attribute 'ElasticNet'
What can I do about it?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.