1+ from sklearn .datasets import load_boston
2+ from sklearn .model_selection import train_test_split
3+ import numpy as np
4+
5+ boston = load_boston ()
6+ X_train , X_test , y_train , y_test = train_test_split (boston .data , boston .target , test_size = 0.2 , random_state = 17 )
7+
8+ def quickregression (name ):
9+ from sklearn .metrics import mean_absolute_error , mean_squared_error , mean_absolute_percentage_error
10+ """
11+ Function to save time when doing Machine Learning models.
12+ It only asks the name of the model to train and returns the scoring.
13+
14+ Parameters
15+ ----------
16+ name = Name of the ML model.
17+ Input Example = LinearRegression
18+
19+ Returns
20+ ----------
21+ MAE, MAPE, MSE, RMSE and R2 Scores.
22+ """
23+
24+ # Fit of the model in the previously split X_train, y_train
25+ model = name ()
26+ model .fit (X_train , y_train )
27+ # Predict of the model with X_test
28+ modpred = model .predict (X_test )
29+ # Scores of the model with y_test and the predict values.
30+ print ("MAE test:" , mean_absolute_error (y_test , modpred ))
31+ print ("MAPE test:" , mean_absolute_percentage_error (y_test , modpred ))
32+ print ("MSE test:" , mean_squared_error (y_test , modpred ))
33+ print ("RMSE test:" , np .sqrt (mean_squared_error (y_test , modpred )))
34+ return (model .score (X_train , y_train ))
0 commit comments