【发布时间】:2021-07-25 10:38:36
【问题描述】:
所以,我正在使用随机森林分类器使用以下代码进行预测:
# Import Random Forest
from sklearn.ensemble import RandomForestClassifier
# Create a Gaussian Classifier
clf_two=RandomForestClassifier(n_estimators=3)
# Train the model using the training sets
clf_two.fit(emb_train, ytrain.ravel())
y_pred_two=clf_two.predict(emb_test)
我想找出我的分类器的准确性并尝试这样做:
# Import scikit-learn metrics module for accuracy calculation
from sklearn import metrics
# Model Accuracy
print("Accuracy:", metrics.accuracy_score(ytrain, y_pred_two))
问题在于y_pred_two 是大小为(5989,) 的行向量,而ytrain 是大小为(16128, 1) 的列向量。所以两者之间存在大小不匹配,我收到此错误:
ValueError: Found input variables with inconsistent numbers of samples: [16128, 5989]
如果y_pred_two 和ytrain 的大小不同或者我做错了什么,是否仍然可以测量准确性?但这就是向我提供训练和测试数据的方式。
我们将不胜感激您的快速帮助!
【问题讨论】:
标签: python classification random-forest