Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions