p ython鸢尾花分类
时间: 2023-07-11 17:32:14 浏览: 137
基于Python BP神经网络实现鸢尾花的分类【100012157】
5星 · 资源好评率100%
你想让我帮你实现Python鸢尾花分类吗?如果是的话,我可以为你提供一个简单的Python代码示例:
```python
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import accuracy_score
# 加载鸢尾花数据集
iris = load_iris()
X = iris.data
y = iris.target
# 划分数据集
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, 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:", accuracy)
```
这段代码使用了sklearn库中的决策树分类器对鸢尾花数据集进行分类,并计算了准确率。希望对你有所帮助!
阅读全文