The Analytic Edge Lecture code in Python Week2 Wine Regression

Week 2 VIDEO 4

Read in data

Linear Regression (one variable)

I will try to use scikit-learn to do modeling in Python

Notice the scikit learn expect X to be a 2-D matrix rather than an 1-D array when fitting the model So simply using['AGST'], wine['Price']) won't work

Or equvalently

There is no simple way to output a detailed summary of the model in scikit-learn like summary(model) in R

You can get the intercept and coefficients of the fitted model like this:

Sum of Squared Errors

If you really wanted detailed statistical summary of the model, take a look at statsmodels rather than scikit-learn

Linear Regression (two variables)

Linear Regression (all variables)

Store the predictors in a list

I guess I should produce a nicer printing...


Remove FrancePop



Pearson correlation coefficient between two variables

Correlation Matrix


Read in test set

Make test set predictions

Compute R-squared

Leave a Reply

Your email address will not be published. Required fields are marked *