发布于2019-08-06 11:30 阅读(5811) 评论(0) 点赞(1) 收藏(3)
成功解决ValueError: Shape of passed values is (1, 332), indices imply (1, 1)
目录
ValueError: Shape of passed values is (1, 332), indices imply (1, 1)
def XGBR_train(X, y):
train_x, test_x, train_y, test_y = train_test_split(X, y, test_size=0.3, random_state=0)
test_preds = pd.DataFrame({"label": test_y}, index=[1,332])
XGBR_model = XGBRegressor(
learning_rate=0.03, # 默认0.3
n_estimators=100, # 树的个数
max_depth=4 )
XGBR_model.fit(train_x, train_y)
test_preds['y_pred'] = XGBR_model.predict(test_x)
XGBR_model_score = metrics.r2_score(test_preds['label'], test_preds['y_pred'])
# GridSearchCV和cross_val_score的结果一样
# scores = cross_val_score(XGBR_model, X, y, scoring='r2')
# print(scores)
# gs = GridSearchCV(XGBR_model, {}, cv=3, verbose=3).fit(X, y)
return XGBR_model, XGBR_model_score
值错误:传递值的形状为(1,332),索引表示(1,1)
可知,形状为一维数据,所以索引只能在数据的维数范围内,不可超出!
作者:来一碗蛋炒饭
链接:https://www.pythonheidong.com/blog/article/8371/af6533540e5701f7cf78/
来源:python黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 python黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-1
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!