Reference no: EM133189705
Assignment - Polynomial Regression I
Details - The purpose of this assignment is expose you to a polynomial regression problem. Your goal is to:
1. Create the following figure using matplotlib, which plots the data from the file called PolynomialRegressionData_I.csv. This figure is generated using the same code that you developed in Assignment 3 of Module 2 - you should reuse that same code.
2. Perform a PolynomialFeatures transformation, then perform linear regression to calculate the optimal ordinary least squares regression model parameters.
3. Recreate the first figure by adding the best fit curve to all subplots.
4. Infer the true model parameters.
Below is the first figure you must emulate:
Below is the second figure you must emulate:
Each of the two figures has four subplots. Note the various viewing angles that each subplot presents - you can achieve this with the view_init() method. Use the same color scheme for the datapoints shown here, which is called jet. Be sure to label your axes as shown.
Create First Image - Use the scatter3D to plot in three dimensions. Create four subplots with the appropriate viewing angles using the view_init() function.
Perform Polynomial Features Transformation - Perform a polynomial transformation on your features.
Train Linear Regression Model - From the sklearn.linear_model library, import the LinearRegression class. Instantiate an object of this class called model, and fit it to the data. x and y will be your training data and z will be your response. Print the optimal model parameters to the screen by completing the following print() statements.
Create Second Image - Use the following x_fit and y_fit data to compute z_fit by invoking the model's predict() method. This will allow you to plot the line of best fit that is predicted by the model.
Infer the True Model Parameters - Provided that the true model parameters are integer values, you are able to infer the true model parameters by rounding the coefficients and the intercept to the nearest integer value. You may "hard-code" these values into the below print statements. (See the assignment 3 template for more information)
Use the get_feature_names() (this has been deprecated -- depending on your version of sklearn, you may need to use get_feature_names_out()) method of the PolynomialFeatures class to be certain of which coefficients you calculated! You need to report your final answers in a format that is abundantly clear to me which which coefficient corresponds to which dependent variable of the model! You may add more print() statements to accomplish this if you must.
Attachment:- Assignment File - Polynomial Regression.rar