Answered step by step
Verified Expert Solution
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 sklearn library for verification only, no credit if you submit sklearn kNN
You are given Xtain, ytrain, Xtest, and ytest subsets of data for ML
You need to complete the following steps:
points
Make a copy of subsets of data to avoid the sharing address problem.
To speed up the computation, select the first samples from training datasets for training, and first sample from testing datasets for testing
Check a shape, b head and c data types of sampled training and testing subsets;
points
Create a function used to calculate average price of kNNs in the training subset for any given testing sample and a given k
Test a sample from the testing subset and compare the kNN price k with the sample real price.
points
Create a function used to find root mean squarederror for all Xtest samples with given k
points
run a loop to find the rmses of all ks in range keep them in a list
This loop will take a while to get outputs.
points
Compare the above rmses step with the given builtin knn model and plot the rmses ~ k
points
run the rest of given codeLinear Decision Tree, Random Forest write a short summary on your observations after comparing your KNN with other algorithms
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