【发布时间】:2021-06-03 15:35:01
【问题描述】:
我正在使用StratifiedShuffleSplit 重复拆分数据集、拟合、预测和计算指标的过程。您能否解释一下为什么每次拆分都给出相同的结果?
import csv
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import StratifiedShuffleSplit
from sklearn.metrics import classification_report
clf = RandomForestClassifier(max_depth = 5)
df = pd.read_csv("https://raw.githubusercontent.com/leanhdung1994/BigData/main/cll_dataset.csv")
X, y = df.iloc[:, 1:], df.iloc[:, 0]
sss = StratifiedShuffleSplit(n_splits = 5, test_size = 0.25, random_state = 0).split(X, y)
for train_ind, test_ind in sss:
X_train, X_test = X.loc[train_ind], X.loc[test_ind]
y_train, y_test = y.loc[train_ind], y.loc[test_ind]
clf.fit(X_train, y_train)
y_pred = clf.predict(X_test)
report = classification_report(y_test, y_pred, zero_division = 0, output_dict = True)
report = pd.DataFrame(report).T
report = report[:2]
print(report)
结果是
precision recall f1-score support
0 0.75 1.0 0.857143 6.0
1 0.00 0.0 0.000000 2.0
precision recall f1-score support
0 0.75 1.0 0.857143 6.0
1 0.00 0.0 0.000000 2.0
precision recall f1-score support
0 0.75 1.0 0.857143 6.0
1 0.00 0.0 0.000000 2.0
precision recall f1-score support
0 0.75 1.0 0.857143 6.0
1 0.00 0.0 0.000000 2.0
precision recall f1-score support
0 0.75 1.0 0.857143 6.0
1 0.00 0.0 0.000000 2.0
【问题讨论】:
标签: python python-3.x scikit-learn random-forest prediction