【发布时间】:2019-08-18 18:39:36
【问题描述】:
我使用随机森林分类器进行分类,并且在每次迭代中我得到不同的结果。我的代码如下。
input_file = 'sample.csv'
df1 = pd.read_csv(input_file)
df2 = pd.read_csv(input_file)
X=df1.drop(['lable'], axis=1) # Features
y=df2['lable'] # Labels
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)
clf=RandomForestClassifier(random_state = 42, class_weight="balanced")
clf.fit(X_train,y_train)
y_pred=clf.predict(X_test)
print("Accuracy:",metrics.accuracy_score(y_test, y_pred))
根据其他answers 的建议,我添加了参数n_estimators 和random_state。但是,它对我不起作用。
我已附上csv文件here:
如果需要,我很乐意提供更多详细信息。
【问题讨论】:
标签: python scikit-learn classification random-forest