Question: Write Python Code: 1.Learning with fixed : Write a function called learnW that will return the w separator based on the input data points and

Write Python Code:

1.Learning with fixed : Write a function called learnW that will return the w separator based on the input data points and a specified number of iterations. Specifically, the function will be called as: learnW(dataTrain, iters) where dataTrain is a numpy array with shape/size [N,7] the first 6 columns are features, the last column is +1 or -1 label; iter is a single number indicating the number of times to loop through all data points before returning w. The function will return a numpy array with shape/size [1,7] where the first six elements are the values of w and the last element is the offset b. Implement learning to minimize the following: argmin + (1 ( + )) + + ( + ( + )) Here, assume =0.1 , = 0.001 . Assume all input data points are used to compute each new update of w and b. Assume w and b is initialized as all 0s.

2. Learning with adaptive s: Write a function called learnWlam that will return the w separator and corresponding s based on the input data points and a specified number of iterations. Specifically, the function will be called as: learnWlam(dataTrain, wInit, lamInit, iters) where dataTrain is a numpy array with shape/size [N,7] the first 6 columns are features, the last column is +1 or -1 label; wInit is a numpy array with shape/size [1,7] the first 6 columns are w1 through w6 and the last column is b; lamInit is a numpy array with shape/size [N,1] containing a non-negative lambda value for each data point in dataTrain; iter is a single number indicating the number of times to loop through all data points before returning w. The function will return a dictionary of 'wFin' and 'lambdaFin' . wFin is a numpy array with shape/size [1,7] where the first six elements are the values of w and the last element is the offset b. lambdaFin is a numpy array with shape/size [N,1] where row k contains the nonnegative lambda corresponding to the kth data point in dataTrain. Implement learning to minimize the following: argmax argmin + (1 ( + )) + + ( + ( + )) Here, assume = 0.001 . Note a Python dictionary may be returned using the syntax: return {'wFin': wFin, 'lambdaFin': lambdaFin } where wFin and lambdaFin are defined within the body of the function definition. Extra note: is not allowed to be negative. I

f you learn a negative , I recommend you automatically result it to 0: if (lam[i]<0) lam[i]=0;

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!