如何展示所有数据集的分类结果?

问题描述 投票:0回答:1

我是 Python 和机器学习编码的新手。我正在做随机森林回归来预测我想要的值(在这个例子中我们称之为 FS1)。当我将我的数据集拆分为 0.7 用于训练和 0.3 用于测试时,我希望看到所有数据集中的预测值而不仅仅是 0.3 测试。我想问一下有没有办法做到这一点? 非常感谢。

This is the example code I got from the github and I modified to my data where FS1 is the value I want to predit

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)
from sklearn.ensemble import RandomForestRegressor
regressor = RandomForestRegressor(n_estimators = 3000, random_state = 100)
regressor.fit(X_train, y_train)
y_pred = regressor.predict(X_test)
df=pd.DataFrame({'Actual':y_test, 'Predicted':y_pred})
df

在这段代码中,我可以看到0.3测试数据的分类结果(预测值)。无论如何要查看其余 0.7 训练数据的预测值。并将分类结果导出为.csv 文件? 非常感谢。

python machine-learning regression random-forest training-data
1个回答
0
投票

如果我理解正确你的问题,你没有预测训练集,你从来没有做过,但出于好奇,你只是打电话:

regressor.predict(X_train)

但一般来说,您可以根据训练数据来定义要测试的回归函数。

但是我认为拟合训练数据然后对其进行预测似乎并不合逻辑,因为你会过度拟合,并且模型会表现得很好fakely

希望对您有所帮助!

© www.soinside.com 2019 - 2024. All rights reserved.