【发布时间】:2021-08-18 07:43:29
【问题描述】:
当我使用 RandomForestRegressor 进行检查时
from sklearn.ensemble import RandomForestRegressor
r=RandomForestRegressor()
r.fit(X_train,y_train)
r.score(X_test,y_test)
我得到 0.9746156332220394
但是当我使用 RandomizedSearchCV
from sklearn.ensemble import RandomForestRegressor
n_estimators = [int(x) for x in np.linspace(start = 100, stop =1200, num = 12)]
max_features = ['auto', 'sqrt']
max_depth = [int(x) for x in np.linspace(5, 30, num = 6)]
min_samples_split = [2, 5, 10, 15, 100]
min_samples_leaf = [1, 2, 5, 10]
from sklearn.model_selection import RandomizedSearchCV
random_grid = {'n_estimators': n_estimators,
'max_features': max_features,
'max_depth': max_depth,
'min_samples_split': min_samples_split,
'min_samples_leaf': min_samples_leaf}
rf=RandomForestRegressor()
rf_random = RandomizedSearchCV(estimator = rf,
param_distributions = random_grid,
scoring='neg_mean_squared_error',
n_iter = 10,
cv = 5,
verbose=2,
random_state=42,
n_jobs = 1)
rf_random.fit(X_train,y_train)
rf_random.score(X_test,y_test)
我收到 -14881793274.345808
那么为什么准确度分数表现如此糟糕
【问题讨论】:
标签: machine-learning regression random-forest cross-validation