【发布时间】:2018-06-05 03:52:15
【问题描述】:
我有一个数据集df_train 和一些标签df_train_labels。
print(df_train.shape)
print(df_train_labels.shape)
输出:
(1460, 6)
(1460,)
和
print(df_train[0:4])
print(df_train_labels[0:4])
输出
OverallQual GrLivArea GarageCars TotalBsmtSF FullBath YearBuilt
0 1 0.000000 1 1 1 1
1 1 0.000000 0 1 0 1
2 0 0.693147 0 2 0 2
3 0 1.098612 1 3 1 3
0 2.505338
1 2.493950
2 2.510994
3 2.472277
Name: SalePrice, dtype: float64
我正在尝试根据这些数据拟合模型:
from sklearn.ensemble import RandomForestClassifier
clf = RandomForestClassifier(n_estimators=10)
clf = clf.fit(df_train, df_train_labels)
但是,最后一行失败并出现此错误:
raise ValueError("Unknown label type: %r" % y_type)
ValueError: Unknown label type: 'continuous'
我查看了here 和here,但没有看到任何与我的问题相关的信息。
知道可能出了什么问题吗?
【问题讨论】:
-
您的问题的答案在您在此处链接的两个帖子中。
df_train_labels包含实数,但您使用的 分类器 需要离散数字 (labels)。也许,你想要RandomForestRegressor而不是RandomForestClassifier。
标签: python pandas dataframe scikit-learn