当前位置:网站首页>Prediction of KNN Iris species after normalization and standardization
Prediction of KNN Iris species after normalization and standardization
2022-04-22 04:47:00 【weixin_ thirty-eight million eight hundred and seventy-one thou】
API
sklearn.neighbors.KNeighborsClassifier(n_neighbors=5,algorithm=‘auto’)
n_neighbors:
int, Optional ( Default = 5),k_neighbors Query the number of neighbors used by default
algorithm:{‘auto’,‘ball_tree’,‘kd_tree’,‘brute’}
Fast k Nearest neighbor search algorithm , The default parameter is auto, It can be understood that the algorithm decides the appropriate search algorithm by itself . besides , Users can also specify their own search algorithm ball_tree、kd_tree、brute Method to search ,
brute It's brute force search , That's linear scanning , When the training set is large , Calculation is very time-consuming .
kd_tree, structure kd A tree data structure that stores data for quick retrieval ,kd Tree is the binary tree in data structure . Trees constructed by median segmentation , Each node is a hyperrectangle , In dimension less than 20 High aging rate .
ball tree To overcome kd The tree was invented due to high-dimensional failure , Its construction process is based on the center of mass C Sum radius r Split sample space , Each node is a hypersphere .
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.neighbors import KNeighborsClassifier
# 1. Get data set
iris = load_iris()
# 2. Basic data processing
# x_train,x_test,y_train,y_test Is the eigenvalue of the training set 、 Test set eigenvalues 、 Training set target value 、 Test set target value
x_train, x_test, y_train, y_test = train_test_split\
(iris.data, iris.target, test_size=0.2, random_state=22)
# 3、 Feature Engineering : Standardization
transfer = StandardScaler()
x_train = transfer.fit_transform(x_train)
x_test = transfer.transform(x_test)
estimator = KNeighborsClassifier(n_neighbors=9)
estimator.fit(x_train, y_train)
y_predict = estimator.predict(x_test)
print(" The predicted result is :\n", y_predict)
print(" Compare the real value with the predicted value :\n", y_predict == y_test)
# Method 2: Direct calculation accuracy
score = estimator.score(x_test, y_test)
print(" Accuracy rate is :\n", score)


fit Represents the calculated mean , And variance
here transfer.fit_transform It means to extract the features of the training set after calculating the mean and variance ,
transfer.transform Represents using the previously instantiated transfer Get the mean and variance for eigenvalue extraction
版权声明
本文为[weixin_ thirty-eight million eight hundred and seventy-one thou]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210804321399.html
边栏推荐
- goland汉化解决方法(下载插件失败的情况下)
- [untitled]
- Sort one
- The website is linked to the gambling dark chain
- Peer interview sharing Lenovo WinForm direction 20220420
- [chestnut sugar GIS] ArcMap - how to make map combination table with buffer
- 博云 BeyondCMP 云管理平台 5.6 版本发布
- 链表第四篇
- Les racines et le contexte de Carina
- vue项目 npm run build 打包项目时为css、js文件加时间戳版本号,防止浏览器缓存
猜你喜欢

2022A特种设备相关管理(电梯)考试题模拟考试题库模拟考试平台操作

2022 question bank and answers of Shandong Province safety officer C certificate special operation certificate examination

2022t elevator repair test exercises and online simulation test

goland汉化解决方法(下载插件失败的情况下)

How to combine acrobat Pro DC with other files to create a single PDF file?

Solution to Chinese translation of GoLand (in case of failure to download plug-ins)

How to realize different values and display different colors in MATLAB

At32 MCU audio 24bit routine

2022 a special equipment related management (elevator) retraining question bank and answers

博云 BeyondCMP 云管理平台 5.6 版本发布
随机推荐
【板栗糖GIS】supermap—如何為數據制造超鏈接
Replace vscode interpreter
POJ - 2456 Aggressive cows (二分 + 贪心)
线程池状态+ThreadPoolExecutor
Cloud network integration - computing power center - roce / rmda and nvme / nvme of
C language learning record -- use and analysis of string function (1)
[twelfth database operation - stored procedure]
Climb the actor's name and add a link
kaggle實戰4.1--時間序列預測問題
Paper reading (49): big data security and privacy protection (Kopp)
LeetCode 剑指 Offer 15. 二进制中1的个数
博云 BeyondCMP 云管理平台 5.6 版本发布
LeetCode 剑指 Offer 68 - I. 二叉搜索树的最近公共祖先
22.4.21学习感悟
Shell variables $, $@, $0, $1, $2, ${},%% use explanation and easy-to-use shell formatting tools
LeetCode 剑指 Offer 18. 删除链表的节点
AT32 MCU F435/437 DFU DEMO
安装opencv时遇到的报错
爬演员名字加链接
资源 ACCP-S1 BOOK3开发工具的下载