data = pdread_excelCUserslenovoDesktopHIVGSE6740GSE50011基因降低dataxlsxX = datailoc 1 # 特征变量y = datailoc 0 # 目标变量
导入所需的包
from sklearn.model_selection import train_test_split from sklearn.tree import DecisionTreeClassifier from sklearn.metrics import accuracy_score
将数据集划分为训练集和测试集
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)
构建决策树分类器
clf = DecisionTreeClassifier(random_state=42)
在训练集上训练模型
clf.fit(X_train, y_train)
在测试集上预测
y_pred = clf.predict(X_test)
计算模型的准确率
accuracy = accuracy_score(y_test, y_pred) print("模型的准确率为:", accuracy)
原文地址: https://www.cveoy.top/t/topic/Dph 著作权归作者所有。请勿转载和采集!