Day 33
2026/8/30 11:29:54 网站建设 项目流程
import pandas as pd from sklearn.datasets import load_iris from sklearn.model_selection import train_test_split from sklearn.ensemble import RandomForestClassifier # 加载鸢尾花数据集 iris = load_iris() df = pd.DataFrame(iris.data, columns=iris.feature_names) df['target'] = iris.target # 添加目标列(0-2类:山鸢尾、杂色鸢尾、维吉尼亚鸢尾) # 特征与目标变量 features = iris.feature_names # 4个特征:花萼长度、花萼宽度、花瓣长度、花瓣宽度 target = 'target' # 目标列名 df # 划分训练集与测试集 X_train, X_test, y_train, y_test = train_test_split( df[features], df[target], test_size=0.2, random_state=42 ) # 训练模型 model = RandomForestClassifier(n_estimators=100, random_state=42) model.fit(X_train, y_train) import pdpbox from pdpbox.info_plots import InteractTargetPlot feature = ['petal length (cm)', 'petal width (cm)'] feature_names = ['petal length (cm)', 'petal width (cm)'] plot = InteractTargetPlot( df = df, features = feature, feature_names = feature_names, target = target ) plot.plot()[0] # plot.plot()[2]

@浙大疏锦行

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询