【发布时间】:2016-09-02 06:14:48
【问题描述】:
我正在使用 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 添加到测试文件中?
【问题讨论】:
-
这不就是
X_test['Prediction'] = preds['Survivied']吗?
标签: python pandas machine-learning random-forest