Home /
Expert Answers /
Computer Science /
requirement-1-use-the-same-functions-create-toy-datao-and-fo-from-assignment-1-task-one-to-gene-pa826
(Solved): Requirement 1. Use the same functions(create toy_dataO and fO) from assignment 1 , task one to gene ...
Requirement 1. Use the same functions(create toy_dataO and fO) from assignment 1 , task one to generate 10 data for training,and 100 samples for testing. 2. Use polynomial basis function(PolynomialFeatures0 from sklearn) to convert your training and testing data into matrix Phi. Set polynomial order =9 3. Now we want to study the dual representation for the following error function: J(W)=21??n=1N?{WT?(xn?)?tn?}2 (Hint you can use LinearRegression 0 from sklearn to train this model) Take a careful look at this loss, if you want to use LinearRegression0, you might want to change some of its default settings. Train the model using your Phi matrix, save the predictions on the test data. and report the test MSE. 4. Now use the dual model(the kemel representation) to make the prediction on the test data. You need to first compute the Gram matrix K, and the vector k(x). Your prediction rule should be similar, but not identical, to eq 6.9 from the textbook. Save the predictions on the test data. and report the test MSE. 5. Compare the predictions from 4 and 5 , are they identical? Why or why not?
Solution:Using the create_toy_data() and f() functions from assignment 1, task one to generate 10 data for training, and 100 samples for testing.import numpy as npimport random# Function to generate toy data