首页 > 分享 > Python 鸢尾花的识别

Python 鸢尾花的识别

最新推荐文章于 2024-08-01 09:22:00 发布

WiChP 于 2021-09-17 00:30:57 发布

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

from sklearn.neighbors import KNeighborsClassifier from sklearn.model_selection import train_test_split from sklearn.preprocessing import MinMaxScaler from sklearn.feature_selection import SelectKBest, f_classif from sklearn.datasets import load_iris load_data = load_iris() # 归一化 scaler = MinMaxScaler() load_data.data = scaler.fit_transform(load_data.data) # 相关系数法 select = SelectKBest(f_classif, k=2) load_data.data = select.fit_transform(load_data.data, load_data.target) # 把数据集和标签划分成训练集和测试集 x_train, x_test, y_train, y_test = train_test_split(load_data.data, load_data.target, test_size=0.2) # 创建KNN分类器 knn = KNeighborsClassifier(n_neighbors=20) # 代入训练集 knn.fit(x_train, y_train) # 预测 y_pre = knn.predict(x_test) total = 0 right = 0 for i in range(y_pre.size): total += 1 if y_test[i] == y_pre[i]: right += 1 print("预测正确率为 : {:.2%}".format(right/total)) print(y_pre) print(y_test)

12345678910111213141516171819202122232425262728293031323334353637

运行截图:
在这里插入图片描述

相关知识

python的鸢尾花数据如何导入
python 鸢尾花数据集下载
用Python识别花卉种类,并自动整理分类!
python 使用Tensorflow训练BP神经网络实现鸢尾花分类
基于python编程的五种鲜花识别
卷积神经网络实现鸢尾花数据分类python代码实现
Python 基于BP神经网络的鸢尾花分类
手把手教你学Python之鸢尾花分类(scikit
Python 下载 鸢尾花数据集并保存到本地
0020期python训练鲜花识别

网址: Python 鸢尾花的识别 https://m.huajiangbk.com/newsview737348.html

所属分类:花卉
上一篇: 一种辣椒花待授粉花朵识别装置
下一篇: 花情播报