Question: 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 [

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!