from pandas import read_csv
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
file = './BBC.csv'
df = read_csv(file)
array = df.values
X = array[:, 0:11]
Y = array[:, 11]
test_size = 0.30
seed = 45
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=test_size, random_state=seed)
model = RandomForestClassifier()
model.fit(X_train, Y_train)
result = model.score(X_test, X_test)
print("Accuracy: %.3f%%") % (result*100.0)
数据集:https://www.dropbox.com/s/ar1c9yuv5x774cv/BBC.csv?dl=0
我遇到了此错误:
分类指标无法处理多类多输出和二进制目标的混合情况
如果我没记错的话,RandomForest应该能够处理两个类(分类)和均值(回归)。我错了吗?
答案 0 :(得分:0)
编辑:
检查您的数据集。因此,对于分类任务,您的问题出在代码中。
result = model.score(X_test, X_test)
请注意,此处的参数应为X_test
和Y_test
-----有点题外话-----
如果要使用RandomForest进行回归,则可能应该调用RandomForestRegressor