Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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==================

image text in transcribed==============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==================

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedPlease 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions

Question

2. Discuss the steps in preparing a manager to go overseas.

Answered: 1 week ago