【发布时间】:2019-06-07 01:47:03
【问题描述】:
我有一个包含两列用户帖子(帖子)和个性类型(类型)的数据集,我需要根据使用此数据集的帖子的个性类型,所以我使用随机森林回归进行预测 这是我的代码:-
df = pd.read_csv('personality_types.csv')
count_vectorizer = CountVectorizer(decode_error='ignore')
X = count_vectorizer.fit_transform(df['posts'])
y = df['type'].values
Xtrain, Xtest, Ytrain, Ytest = train_test_split(X, y, test_size=0.33)
random_forest = RandomForestClassifier(n_estimators=100)
random_forest.fit(Xtrain, Ytrain)
Y_prediction = random_forest.predict(Xtest)
准确度:
random_forest.score(Xtrain, Ytrain)
acc_random_forest = round(random_forest.score(Xtrain, Ytrain) * 100, 2)
print(round(acc_random_forest,2,), "%")
100%
现在我想从自定义文本中获得预测,我该如何实现? 如何使用此模型分别获取帖子的个性类型。
【问题讨论】:
标签: python machine-learning scikit-learn random-forest