并不需要外来数据集,只需要下载出相对应的库即可
# 导入所需库
from sklearn.datasets import load_wine
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score, classification_report
# 加载数据集
wine_data = load_wine()
X = wine_data.data
Y = wine_data.target
# 划分数据集
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.3, random_state=42)
# 创建并训练模型
model = RandomForestClassifier(n_estimators=50)
model.fit(X_train, Y_train)
# 预测
Y_pred = model.predict(X_test)
# 评估模型
accuracy = accuracy_score(Y_test, Y_pred)
print("Accuracy:", accuracy)
report = classification_report(Y_test, Y_pred)
print("Classification Report:\n", report)
结果展示: