Try to Evaluate
Letβs see which model is better using the metrics we already know.
MSE:
123from 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))
Output:
0.28
0.27
MAE:
123from 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))
Output:
0.45
0.43
R-squared:
123from 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))
Output:
0.53
0.55
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.
Swipe to start coding
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
.
Solution
Thanks for your feedback!
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Summarize this chapter
Explain the code in file
Explain why file doesn't solve the task
Awesome!
Completion rate improved to 4.76
Try to Evaluate
Swipe to show menu
Letβs see which model is better using the metrics we already know.
MSE:
123from 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))
Output:
0.28
0.27
MAE:
123from 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))
Output:
0.45
0.43
R-squared:
123from 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))
Output:
0.53
0.55
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.
Swipe to start coding
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
.
Solution
Thanks for your feedback!
Awesome!
Completion rate improved to 4.76single