鸢尾花分类python算法代码
时间: 2023-10-05 22:14:31 浏览: 119
python机器学习入门,KNN鸢尾花分类
5星 · 资源好评率100%
import pandas as pd
from sklearn.naive_bayes import GaussianNB
from sklearn.metrics import classification_report
from sklearn.model_selection import train_test_split
data_iris = pd.read_csv('iris.csv', index_col=0)
X = data_iris.iloc[:, :-1]
y = data_iris.iloc[:, -1]
X_tr, X_ts, y_tr, y_ts = train_test_split(X, y, test_size=0.2)
model = GaussianNB()
model.fit(X_tr, y_tr)
y_pred = model.predict(X_ts)
classification_result = classification_report(y_pred, y_ts)
print(classification_result)
阅读全文