0
我正在尝试使用SciKit-Learn的网格搜索来查找我的随机森林的最佳参数。我这样做如下:从SKLearn使用GridSearchCV时的JobLibValueError
from sklearn.metrics import classification_report
from sklearn.pipeline import Pipeline
from sklearn.grid_search import GridSearchCV
pipeline = Pipeline([('clf', RandomForestRegressor(random_state=50))])
parameters = {
'clf__n_estimators': (50, 100, 200),
'clf__max_depth': (50, 150, 250),
'clf__min_samples_split': (1, 2, 3, 4, 5),
'clf__min_samples_leaf': (1, 2, 3, 4, 5)
}
grid_search = GridSearchCV(pipeline, parameters, n_jobs=-1,verbose=1, scoring='neg_mean_squared_error')
grid_search.fit(X, Y)
print 'Best score: %0.3f' % grid_search.best_score_
print 'Best parameters set:'
best_parameters = grid_search.best_estimator_.get_params()
for param_name in sorted(parameters.keys()):
print '\t%s: %r' % (param_name, best_parameters[param_name])
predictions = grid_search.predict(X)
print classification_report(Y, predictions)
不幸的是,我得到一个JobLibValueError
指向:
---> 14 grid_search.fit(X, Y)
仅供参考,我的X是这样的:
0 1 2 3 4 5 6 7 8 9 ... 76613 76614 76615 76616 76617 76618 76619 76620 _engaged_time _title
0 0.0 0.000000 0.000000 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 20000.0 54
1 0.0 0.000000 0.000000 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 55000.0 40
和我Y值只是一群参与时间(整数)。
感谢您的帮助!
你能发布完整的堆栈跟踪错误吗? –
你为什么要添加一个单独的操作到'Pipeline'? –
我发布了一个可能的解决方案。你可以上传X和Y来尝试重现错误吗? – sera