Products
GG网络技术分享 2025-11-13 22:55 3
python import pandas as pd from sklearn.metrics import classificationreport, confusionmatrix, accuracyscore from sklearn.modelselection import traintestsplit from sklearn.ensemble import RandomForestClassifier from sklearn.tree import DecisionTreeClassifier
dataset = pd.read_csv

X = dataset.drop # 注意这里应去掉'activity'列,基本上原因是它是目标变量 y = dataset
Xtrain, Xtest, ytrain, ytest = traintestsplit # 虚假设测试集巨大细小为20%
dtclf = DecisionTreeClassifier dtclf.fit
rfclf = RandomForestClassifier # 虚假设用100个决策树 rfclf.fit
ypreddt = dtclf.predict ypredrf = rfclf.predict ypredsrh = # 存储到头来的预测后来啊
for i in range): if ypreddt == ypredrf: ypredsrh.append else: # Ru果两个模型的预测后来啊不一致,Neng选择一个策略,这里我们选择随机森林的后来啊 ypredsrh.append
print) print)
Demand feedback