Question: Requirements: Implement K nearest neighbors algorithm to predict the housing median value ( using sk - learn library for verification only, no credit if you

Requirements: Implement K nearest neighbors algorithm to predict the housing median value
(using sk-learn library for verification only, no credit if you submit sk-learn k-NN )
- You are given X_tain, y_train, X_test, and y_test 4 subsets of data for ML.
- You need to complete the following steps:
(1)(5 points)
- Make a copy of 4 subsets of data to avoid the sharing address problem.
- To speed up the computation, select the first 5000 samples from training datasets for training, and first 1000 sample from testing datasets for testing
- Check (a) shape, (b) head(), and (c) data types of 4 sampled training and testing subsets;
(2)(10 points)
- Create a function used to calculate average price of k-NN's in the training subset for any given testing sample and a given k
- Test a sample from the testing subset and compare the k-NN price (k=5) with the sample real price.
(3)(10 points)
- Create a function used to find root mean squared-error for all 1000 X_test samples with given k =5
(4)(5 points)
- run a loop to find the rmses of all k's in range(1,31,5), keep them in a list
** This loop will take a while to get outputs.
(5)(5 points)
- Compare the above rmses (step 4) with the given built-in knn model and plot the rmses ~ k
(6)(5 points)
- run the rest of given code(Linear, Decision Tree, Random Forest), write a short summary on your observations after comparing your K-NN with other 4 algorithms

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!