python-GridSearchCV错误:应为类数组(数组或非字符串序列),获取
发布时间:2022-08-29 15:48:54 341
相关标签: # node.js
我目前正在使用H20建模,但我正在使用Scikit学习管道。
- 首先,我使用以下代码创建了基线模型:
clf_pipe = Pipeline(
steps = [("impute missing", replace_missing_vars),
("scale", scale),
("dim_reduction", pca),
("classifier", gbm)])
clf = clf_pipe.fit(train[x], train[y])
r2 = clf[len(clf)-1].r2(test[x], test[y])
- 现在,我想通过运行gridsearch对模型进行超调谐,如下所示:
parameters = {'ntree': [24, 50, 100], 'max_depth': [5,10], 'learn_rate':[0.25, 0.5, 0.65]}
gs_clf = GridSearchCV(clf_pipe, param_grid=params)
clf = gs_clf.fit(train[x], train[y])
- 但我得到了以下明确的错误消息(它不是不完整的,它的结尾是这样的):
/usr/local/lib/python3.7/site-packages/sklearn/utils/multiclass.py in type_of_target(y)
239 if not valid:
240 raise ValueError('Expected array-like (array or non-string sequence), '
--> 241 'got %r' % y)
242
243 sparse_pandas = (y.__class__.__name__ in ['SparseSeries', 'SparseArray'])
ValueError: Expected array-like (array or non-string sequence), got
如果您想知道列车数据是什么样子的,这是数据帧结构:
trin[x] = {'nartd_share': 'real',
'nanrtd_share': 'real',
'hot_beverages_share': 'real',
'alcoholic_beverages_share': 'real',
'all_beverages_share': 'int',
'pfand_share': 'int',
'if_top7_cities': 'enum',
'opening_days': 'real',
'opening_hours': 'real',
'closing_hours': 'real',
'open_at_b_of': 'real',
'close_at_e_of': 'real',
'busiest_at': 'real',
'most_revenue_at': 'real',
'opening_at_cosine': 'real',
'closing_at_cosine': 'real',
'busiest_at_cosine': 'real',
'most_revenue_at_cosine': 'real',
'weekend_opening_hours': 'real',
'weekday_opening_hours': 'real',
'avg_overnight_hours': 'real',
'if_overnight': 'enum',
'if_sunday': 'enum',
'monthly_revenue': 'real',
'monthly_quantity': 'real',
'monthly_alcohol_revenue': 'real',
'monthly_7vat_share': 'real',
'weekly_revenue': 'real',
'weekly_quantity': 'real',
'weekly_alcohol_revenue': 'real',
'weekly_7vat_share': 'real',
'daily_revenue': 'real',
'daily_quantity': 'real',
'daily_alcohol_revenue': 'real',
'daily_7vat_share': 'real',
'avg_alcohol_price': 'real',
'avg_nartd_price': 'real',
'max_alcohol_price': 'real',
'max_nartd_price': 'real',
'top1_product': 'enum',
'top2_product': 'enum',
'top3_product': 'enum'}
train[y] = {'segment': 'enum'}
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报