Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1- Use the following libraries. import numpy as np from sklearn import datasets from sklearn. neighbors import KNeighborsClassifier from sklearn.model_selection import train_test_split 2- Load Iris
1- Use the following libraries. import numpy as np from sklearn import datasets from sklearn. neighbors import KNeighborsClassifier from sklearn.model_selection import train_test_split 2- Load Iris dataset. 2- Split the data set into train and test subsets. X_train, X_test, y_train, y_test = train_test_split (x,y, test_size =0.3, random_state= 0) 3- Train a KNN classifier with the train set. knn=KNeighborsClassifier(n_neighbors=3) knn.fit(X_train, y_train) 4- Test the KNN classifier with the test subset. y_pred =knnpredict(X_test ) 5- Find the accuracy of the classifier through comparing the predicted labels ( y pred) with the true labels (y_test) in a dataset. 6- Change number of neighbors (n_neighbors) and the test subset size (test_size) and report the accuracy of the classifier
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started