Course Content
Explore the Linear Regression Using Python
Explore the Linear Regression Using Python
Try to Evaluate
Let’s see which model is better using the metrics we already know.
MSE:
from sklearn.metrics import mean_squared_error print(mean_squared_error(Y_test, y_test_predicted).round(2)) print(mean_squared_error(Y_test, y_test_predicted2).round(2))
MAE:
from sklearn.metrics import mean_absolute_error print(mean_absolute_error(Y_test, y_test_predicted).round(2)) print(mean_absolute_error(Y_test, y_test_predicted2).round(2))
R-squared:
from sklearn.metrics import r2_score print(r2_score(Y_test, y_test_predicted).round(2)) print(r2_score(Y_test, y_test_predicted2).round(2))
As a general rule, the more features a model includes, the lower the MSE (RMSE) and MAE will be. However, be careful about including too many features. Some of them may be extremely random, degrading the model's interpretability.
Task
Let’s evaluate the model from the previous task:
- [Line #30] Import
mean_squared_error
for calculating metrics fromscikit.metrics
. - [Line #31] Find MSE using method
mean_squared_error()
andY_test
,y_test_predicted2
as the parameters, assign it to the variableMSE
, round the result to second digit. - [Line #32] Print the variable
MSE
. - [Line #35] Import
r2_score
fromscikit.metrics
. - [Line #36] Find R-squared and assign it to the variable
r_squared
, round the result to second digit. - [Line #37] Print the variable
r_squared
.
Thanks for your feedback!
Try to Evaluate
Let’s see which model is better using the metrics we already know.
MSE:
from sklearn.metrics import mean_squared_error print(mean_squared_error(Y_test, y_test_predicted).round(2)) print(mean_squared_error(Y_test, y_test_predicted2).round(2))
MAE:
from sklearn.metrics import mean_absolute_error print(mean_absolute_error(Y_test, y_test_predicted).round(2)) print(mean_absolute_error(Y_test, y_test_predicted2).round(2))
R-squared:
from sklearn.metrics import r2_score print(r2_score(Y_test, y_test_predicted).round(2)) print(r2_score(Y_test, y_test_predicted2).round(2))
As a general rule, the more features a model includes, the lower the MSE (RMSE) and MAE will be. However, be careful about including too many features. Some of them may be extremely random, degrading the model's interpretability.
Task
Let’s evaluate the model from the previous task:
- [Line #30] Import
mean_squared_error
for calculating metrics fromscikit.metrics
. - [Line #31] Find MSE using method
mean_squared_error()
andY_test
,y_test_predicted2
as the parameters, assign it to the variableMSE
, round the result to second digit. - [Line #32] Print the variable
MSE
. - [Line #35] Import
r2_score
fromscikit.metrics
. - [Line #36] Find R-squared and assign it to the variable
r_squared
, round the result to second digit. - [Line #37] Print the variable
r_squared
.
Thanks for your feedback!
Try to Evaluate
Let’s see which model is better using the metrics we already know.
MSE:
from sklearn.metrics import mean_squared_error print(mean_squared_error(Y_test, y_test_predicted).round(2)) print(mean_squared_error(Y_test, y_test_predicted2).round(2))
MAE:
from sklearn.metrics import mean_absolute_error print(mean_absolute_error(Y_test, y_test_predicted).round(2)) print(mean_absolute_error(Y_test, y_test_predicted2).round(2))
R-squared:
from sklearn.metrics import r2_score print(r2_score(Y_test, y_test_predicted).round(2)) print(r2_score(Y_test, y_test_predicted2).round(2))
As a general rule, the more features a model includes, the lower the MSE (RMSE) and MAE will be. However, be careful about including too many features. Some of them may be extremely random, degrading the model's interpretability.
Task
Let’s evaluate the model from the previous task:
- [Line #30] Import
mean_squared_error
for calculating metrics fromscikit.metrics
. - [Line #31] Find MSE using method
mean_squared_error()
andY_test
,y_test_predicted2
as the parameters, assign it to the variableMSE
, round the result to second digit. - [Line #32] Print the variable
MSE
. - [Line #35] Import
r2_score
fromscikit.metrics
. - [Line #36] Find R-squared and assign it to the variable
r_squared
, round the result to second digit. - [Line #37] Print the variable
r_squared
.
Thanks for your feedback!
Let’s see which model is better using the metrics we already know.
MSE:
from sklearn.metrics import mean_squared_error print(mean_squared_error(Y_test, y_test_predicted).round(2)) print(mean_squared_error(Y_test, y_test_predicted2).round(2))
MAE:
from sklearn.metrics import mean_absolute_error print(mean_absolute_error(Y_test, y_test_predicted).round(2)) print(mean_absolute_error(Y_test, y_test_predicted2).round(2))
R-squared:
from sklearn.metrics import r2_score print(r2_score(Y_test, y_test_predicted).round(2)) print(r2_score(Y_test, y_test_predicted2).round(2))
As a general rule, the more features a model includes, the lower the MSE (RMSE) and MAE will be. However, be careful about including too many features. Some of them may be extremely random, degrading the model's interpretability.
Task
Let’s evaluate the model from the previous task:
- [Line #30] Import
mean_squared_error
for calculating metrics fromscikit.metrics
. - [Line #31] Find MSE using method
mean_squared_error()
andY_test
,y_test_predicted2
as the parameters, assign it to the variableMSE
, round the result to second digit. - [Line #32] Print the variable
MSE
. - [Line #35] Import
r2_score
fromscikit.metrics
. - [Line #36] Find R-squared and assign it to the variable
r_squared
, round the result to second digit. - [Line #37] Print the variable
r_squared
.