Есть ли лучший способ протестировать или оценить RandomForestRegressor ()? - PullRequest
0 голосов
/ 13 июля 2020

Я искал лучший способ сделать некоторые прогнозы и хотел использовать одну из моделей ансамбля в Python, такую ​​как RandomForestRegressor (). Я начал со следующего блока кода, и он вернул MAE: -90.237 (8.148).

Вот как выглядят мои данные tes:

[[-0.89483109 -1.0670149  -0.25448694 ... -0.17571721 -1.11454339
   0.36268268]
 [ 0.17028716  0.15269737 -0.39383676 ...  1.40996923 -0.63753188
   1.49974303]
 [-0.51636749  2.65981438 -1.03243014 ...  1.37199807  0.79948847
   0.88506807]
 ...
 [-0.77976473 -1.55479663  1.76729968 ...  3.49187693  0.00762306
   0.14074023]
 [ 0.47129989 -0.93171375 -0.5609986  ... -0.568612    0.24103721
   0.15164709]
 [-0.77994308  1.52251483 -1.63972576 ...  0.22623415  0.19716891
  -0.32752818]]

Это код RandomForestRegressor ()

# evaluate random forest ensemble for regression
from numpy import mean
from numpy import std
from sklearn.datasets import make_regression
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import RepeatedKFold
from sklearn.ensemble import RandomForestRegressor
# define dataset
X, y = make_regression(n_samples=1000, n_features=20, n_informative=15, noise=0.1, random_state=2)
# define the model
model = RandomForestRegressor()
# evaluate the model
cv = RepeatedKFold(n_splits=10, n_repeats=3, random_state=1)
n_scores = cross_val_score(model, X, y, scoring='neg_mean_absolute_error', cv=cv, n_jobs=-1, error_score='raise')
# report performance
print('MAE: %.3f (%.3f)' % (mean(n_scores), std(n_scores)))

Однако, когда я заменяю случайные тестовые данные моими собственными данными, мой показатель MAE кажется далеким от нормы: MAE: -0.095 (0.008)

Вот что я данные выглядят так:

df_train shape:  (1458, 220)
   MSSubClass  LotFrontage   LotArea  Street  Alley  LotShape  LandSlope  \
0           5     4.189655  9.042040       1      1         3          0   
1           0     4.394449  9.169623       1      1         3          0   
2           5     4.234107  9.328212       1      1         0          0   
3           6     4.110874  9.164401       1      1         0          0   
4           5     4.442651  9.565284       1      1         0          0   

   OverallQual  OverallCond  YearBuilt  ...  SaleType_ConLw  SaleType_New  \
0            6            4   7.602900  ...               0             0   
1            5            7   7.589336  ...               0             0   
2            6            4   7.601902  ...               0             0   
3            6            4   7.557995  ...               0             0   
4            7            4   7.601402  ...               0             0   

   SaleType_Oth  SaleType_WD  SaleCondition_Abnorml  SaleCondition_AdjLand  \
0             0            1                      0                      0   
1             0            1                      0                      0   
2             0            1                      0                      0   
3             0            1                      1                      0   
4             0            1                      0                      0   

   SaleCondition_Alloca  SaleCondition_Family  SaleCondition_Normal  \
0                     0                     0                     1   
1                     0                     0                     1   
2                     0                     0                     1   
3                     0                     0                     0   
4                     0                     0                     1   

   SaleCondition_Partial  
0                      0  
1                      0  
2                      0  
3                      0  
4                      0  
model = RandomForestRegressor()

# define dataset
# X, y = make_regression(n_samples=1000, n_features=20, n_informative=15, noise=0.1, random_state=2)
X = df_train; y = y_train

# evaluate the model
cv = RepeatedKFold(n_splits=10, n_repeats=3, random_state=1)
n_scores = cross_val_score(model, X , y, scoring='neg_mean_absolute_error', cv=cv, n_jobs=-1, error_score='raise')
# report performance
print('MAE: %.3f (%.3f)' % (np.mean(n_scores), np.std(n_scores)))

Что именно это означает? Эта модель не может работать с моими Данными или я делаю это неправильно, чтобы получить правильный ответ?

...