Lesson 5 ❮ Lesson List ❮ Top Page
5.1 Preprocessing with sklearn
❯ 5.2 Linear Regression
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
EXPECTED COMPLETION TIME
❲▹❳ Video 7m 49s
☷ Interactive readings 5m
Making the Model
Linear regression can be used to predict numerical attributes. The regression class in Scikit-learn is part of the linear_model module.
We will scale the data first using scale and we will see how to fit our data into the model.
Showing the Regression Coefficients & Score
We can use the scoring method to report the R^2 measure (ranges from 0 to 1). The closer the number to 1, the better the model.
To see which attributes affect the estimation the most in the multiple regression model, you have to look at the coef_ attribute, which is an array containing the regression coefficients. The highest the absolute value, the more it affects the model.
You can also see the intercept using intercept_
Finally, the zip function will generate an iterable of both attributes, and you can print it for reporting.
Plotting the Regression Line
While we cannot plot more than two dimension, we can try to plot two variables to see what the regression line looks like by using regplot in seaborn library.