Answered step by step
Verified Expert Solution
Question
1 Approved Answer
2.2 Splitting our dataset into training data and test data [ ]: from sklearn.cross_validation import train_test_split X_train, X_test, y_train, y_test = train_test_split cancer_dataset [ 'data'],
2.2 Splitting our dataset into training data and test data [ ]: from sklearn.cross_validation import train_test_split X_train, X_test, y_train, y_test = train_test_split cancer_dataset [ 'data'], cancer_dataset [ 'target' ], random_state =0 ) 2.3 K Nearest Neighbours We will now learn how to build a classification model for the breast cancer dataset with the use of the k nearest neighbours algorithm. Building and evaluating the model for 1 nearest neighbour Run the code below to create a KNeighborsClassifier model called knn_model. Note that n_neighbors =1 is setting the number of nearest neighbours to 1 . [ ]: from sklearn.neighbors import KNeighborsClassifier knn_model = KNeighborsClassifier (n_neighbors =1 ) knn_model.fit(X_train, y_train) [ ]: print("Test set score: {:.3f} ". format(knn_model.score(X_test, y_test))) Quiz Question 7 Write your code in the next cell(s) to build and evaluate a K Nearest Neighbours model for 5 neighbours. [ ]
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