(0 pts) Investigate the abalone dataset Download abalone dataset
(3 pts) Save the Rings value (Rings) in a separate vector/data frame called target_data.
(3 pts) Encode all categorical columns and Normalize all the columns in train_data using min-max normalization.
(15 pts) Build a function called reg that implements a regression version of kNN that averages the value of the Rings of the k nearest neighbors using a weighted average where the weight is 3 for the closest neighbor, 2 for the second closest, and 1 for the remaining neighbors (recall that a weighted average requires that you divide the sum product of the weight and values by the sum of the weights). It must use the following signature: knn.reg (new_data, target_data, train_data, k) where new_data is a data frame with new cases, target_data is a data frame with a single column of Rings value from (2), train_data is a data frame with the features from (2) that correspond to a Rings value in target_data, and k is the number of nearest neighbors to consider. It must return the predicted value of the Rings. Use k = 5.
Copyright By PowCoder代写 加微信 powcoder
(4 pts) Forecast the number of Rings of this new abalone using your regression kNN using k = 5:Sex: F | Length: 0.43 | Diameter: 0.482 | Height: 0.25 | Whole weight: 0.4653 | Shucked weight: 0.2632 | Viscera weight: 0.0987 | Shell weight: 0.20.
(5 pts) Calculate the Mean Squared Error (MSE) using a random sample of 10% of the data set as test data.
The code needs to be carefully constructed for efficiency so that questions (5) and (6) have a reasonable chance of completing. Otherwise, it can take too long to run. Common problems are loops and the dynamic creation of data frames: pre-allocate memory and use which, vector calculations, and apply when possible, rather than loops. Use Sys.time to measure the run time of parts of code to determine bottlenecks and use the resources on optimizing R code below — the same strategies often apply to Python as well.
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com