Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please solve this using python. Please show the code and explain! Question 1. Exact Adaline Weights In the class we discussed gradient descent for computing
Please solve this using python. Please show the code and explain!
Question 1. Exact Adaline Weights In the class we discussed gradient descent for computing the weights of Adaline. It is possible however to use an 'exact' solver: Suppose X is the data matrix, with shape n xd, where d is the number of attributes. Now let's augment X by adding one extra attribute/column on the left side of X with all entries being equal to 1. Let X be this new matrix (this step reflects that xo = 1). Also, let w be the vector of weights (with shape (d + 1) x 1, and y be the vector of labels (with shape (n + 1) x 1). It turns out that the optimal weight vector w is given by w = (x+x)-'xTy (i) Write a Python function exactAdaline (using numpy) that takes as input X and y and returns the optimal. weights w, following the above formula (ii) Apply the function on the iris dataset that you imported in an earlier cell. Report the weights calculated by the function. (iii) The total error for a vector w is given by this formula err = ||Xw yll The subscript of the norm means the 2-norm. Use numpy to do your calculation. (Please insert cells below for your answers. Clearly id the part of the question you answer) In [ ]: N Question 1. Exact Adaline Weights In the class we discussed gradient descent for computing the weights of Adaline. It is possible however to use an 'exact' solver: Suppose X is the data matrix, with shape n xd, where d is the number of attributes. Now let's augment X by adding one extra attribute/column on the left side of X with all entries being equal to 1. Let X be this new matrix (this step reflects that xo = 1). Also, let w be the vector of weights (with shape (d + 1) x 1, and y be the vector of labels (with shape (n + 1) x 1). It turns out that the optimal weight vector w is given by w = (x+x)-'xTy (i) Write a Python function exactAdaline (using numpy) that takes as input X and y and returns the optimal. weights w, following the above formula (ii) Apply the function on the iris dataset that you imported in an earlier cell. Report the weights calculated by the function. (iii) The total error for a vector w is given by this formula err = ||Xw yll The subscript of the norm means the 2-norm. Use numpy to do your calculation. (Please insert cells below for your answers. Clearly id the part of the question you answer) In [ ]: N
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started