为了账号安全,请及时绑定邮箱和手机立即绑定

拆分数据集以按行进行训练和测试

拆分数据集以按行进行训练和测试

月关宝盒 2021-06-29 18:55:48
我想根据年份将我的数据集拆分为训练和测试数据集。这个想法是将年份范围为 2009-2017 的行放入训练数据集中,将 2018 年的数据放入测试数据集中。大多数情况下,拆分数据集很容易,但我的模型引发了很多索引问题。X = ((df[df['Year'] < 2018]))X_train = np.array(X.drop(['Usage'], 1))X_test = np.array(X['Usage'])y =((df[df['Year'] > 2017]))y_train = np.array(y.drop(['Usage'], 1))y_test = np.array(y['Usage'])这就是我计划拆分数据的方式。使用列是我的预测列,包含连续值。应用一个简单的 RandomForestRegressor() 给了我这个错误作为回报ValueError: Number of labels=14495 does not match number of samples=382772aditya 我的回归模型非常基本,但我以任何方式附加代码。在 X 中传递的列如下: X= [Cust_Id', 'Usage', 'Plan_Group', 'Contract_Type', 'Cust_Status','Premise_Zip', 'Year', 'Month']model = RandomForestRegressor()model.fit(X_train, y_train)y_pred = model.predict(X_test)# evaluate predictionsprint(model.score(X_test, y_test))# accuracy = accuracy_score(y_test, (y_pred < 0.5).astype(int))
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 344 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号