我正在python pandas
(在Jupyter
笔记本中)中工作,在那里我为泰坦尼克号数据集创建了一个随机林模型。
https://www.kaggle.com/c/titanic/data
我读入测试和训练数据,然后清理它并添加新列(两个列都是相同的列)
在对模型进行了拟合和重新拟合,并尝试了升压等;我决定采用一种模式:
X2 = train_data[['Pclass','Sex','Age','richness']]
rfc_model_3 = RandomForestClassifier(n_estimators=200)
%time cross_val_score(rfc_model_3, X2, Y_target).mean()
rfc_model_3.fit(X2, Y_target)
然后我预测,如果有人幸存或没有
X_test = test_data[['Pclass','Sex','Age','richness']]
predictions = rfc_model_3.predict(X_test)
preds = pd.DataFrame(predictions, columns=['Survived'])
有没有办法将预测作为column
添加到测试文件中
自
返回
y : array of shape = [n_samples]
(see docs),您应该能够直接将模型输出添加到X_test
,而无需创建中间DataFrame
:如果你想得到中间结果,@EdChum在评论中的建议也行
相关问题 更多 >
编程相关推荐