Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE SOLVE USING PYTHON 3 Question 2 [ 5 pts] You are given a linear regression problem (with two independent variables) in the attached Jupyter

PLEASE SOLVE USING PYTHON

image text in transcribedimage text in transcribedimage text in transcribed

3 Question 2 [ 5 pts] You are given a linear regression problem (with two independent variables) in the attached Jupyter Notebook file (HW2 - Question 3.ipynb). Solve the problem with the gradient descent algorithm using Standard Scaling (see StandardScaler in scikit-learn). Gradient Descent: Linear regression with two variables In this homewrok you are going to solve a linear regression problem with 2 variables and 1000 observations. Let us create and load the data. from sklearn.linear_model import LinearRegression from sklearn.datasets import make_regression X,Y= make_regression(n_samples =1000,nfeatures=2, n_informative =2, n_targets =1, bias =10, coef= False, noise =20, random_state =0 ) Derivatives Our model has two features (X) and a target value (Y). We try to find the optimal values of 0,1,2 to minimize the error term, where y^i=0+1xi,1+2xi,2 for the observation i.xi,1 corresponds to the value of the first feature for observation i and xi,2 corresponds to the value of the second feature for observation i. The error term (for the mean squared error or MSE) becomes MSE=10001i=11000(yiy^i)2=10001i=11000(yi01xi,12xi,2)2 Then the partial derivatives with respect to 0,1,2 become: 0MSE=10001i=110002(yi01xi,12xi,2) 1MSE=10001i=110002xi,1(yi01xi,12xi,2) Solve the given linear regression problem using gradient descent and scaling. You will start from the solution 0=0,1=0,2=0. The maximum number of iterations is 1000 , you are required to find a suitable stepsize. Do not forget to scale your data set ( your coefficients will be different from the ones above after scaling). beta=0beta1=0beta2=0 n_iters =1000 \#Maximum number of iterations precision =0.0001# The precision value to stop the algorithm File "", line 9 Syntaxerror: invalid syntax

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

Repairing And Querying Databases Under Aggregate Constraints

Authors: Sergio Flesca ,Filippo Furfaro ,Francesco Parisi

2011th Edition

146141640X, 978-1461416401

More Books

Students also viewed these Databases questions