Question: Python please!!!I hope you can help me with Problem 6. Thank you! Here is the data set and code for previous question (Problem 2), which

Python please!!!I hope you can help me with Problem 6. Thank you!

Here is the data set and code for previous question (Problem 2), which is relevant with Problem 6.

==============Code Chunk==================

from sklearn.linear_model import LinearRegression import pandas as pd import pylab as plt import seaborn import numpy.random as nprnd import random

%matplotlib inline

# Import data df = pd.read_csv('http://www-bcf.usc.edu/~gareth/ISL/Advertising.csv', index_col=0) df.head()

==============Code Chunk==================

Python please!!!I hope you can help me with Problem 6. Thank you!==============Code Chunk==================

from sklearn.linear_model import LinearRegression from sklearn.model_selection import train_test_split

# Set y to be the sales in df y = df['sales']

# Set X to be just the features described above in df, also create a new column called interecept which is just 1. X = df.drop(['sales'],1)

# Randomly split data into training and testing - 80% training, 20% testing. X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Create linear regression object regr = LinearRegression()

# Train the model using the training sets regr.fit(X_train, y_train)

# The coefficients print('Coefficients: ', regr.coef_) ==============Code Chunk==================

Here is the data set and code for previous question (Problem 2),which is relevant with Problem 6. ==============Code Chunk================== from sklearn.linear_model import LinearRegressionimport pandas as pd import pylab as plt import seaborn import numpy.randomas nprnd import random %matplotlib inline # Import data df = pd.read_csv('http://www-bcf.usc.edu/~gareth/ISL/Advertising.csv',index_col=0) df.head() ==============Code Chunk================== ==============Code Chunk================== from sklearn.linear_model import LinearRegression from sklearn.model_selectionPlease provide relevant answers and Python code. (Screenshots of your Jupyter Notebook are okay!!! )

Out [3]: 1 230.1 37.8 2 44.5 39.3 3 17.2 45.9 4 151.5 41.3 5 180.8 10.8 TV radio newspaper sales 69.2 22.1 45.1 10.4 69.3 9.3 58.5 18.5 58.4 12.9 What are the features (variables, covariates, all mean the same thing)? TV: advertising dollars spent on TV for a single product in a given market (in thousands of dollars) Radio: advertising dollars spent on Radio Newspaper: advertising dollars spent on Newspaper . Sales: Number of 1k units sold Goal: Predict the amount of sales in a given market based on the advertising in TV, Radio and Newspaper. Problem 6 : Computing to Problem 2 via gradient descent. Let where (x. y) are as in Problem 2. [10 points] a) Solve VF(B) - 0 for B in terms of X and y and show that the solution is Hint: Use the product rule for inner products afer rewriting [10 points] d) Repeat part c) but for your scaled features. Do you notice that you can obtain convergence with a lower number of iterations and higher learning rate? Explain why rescaling your features could have this impact. from sklearn import preprocessing X_scaledpreprocessing. scale (X) v scaled v np, mean (v) [10 points] e) Finally consider the Lasso regularized OLS FAA : i=1 using the optimal found in Problem 4, rewrite your gradient descent algorithm for this reguarlized norm. Ensure you used your scaled features

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!