Question: Linear Regression model import numpy as np class Linear ( object ) : def _ _ init _ _
Linear Regression model
import numpy as np
class Linearobject:
def initself nclass: int, lr: float, epochs: int, weightdecay: float:
Initialize a new classifier.
Parameters:
nclass: the number of classes
lr: the learning rate
epochs: the number of epochs to train for
self.w None # Initialize in train
self.lr lr
self.epochs epochs
self.nclass nclass
self.weightdecay weightdecay
def trainself Xtrain: npndarray, ytrain: npndarray, weights: npndarray npndarray:
Train the classifier.
Use the linear regression update rule as introduced in the Lecture.
Parameters:
Xtrain: a number array of shape N D containing training data;
N examples with D dimensions
ytrain: a numpy array of shape N containing training labels
N D Xtrain.shape
self.w weights
# TODO: implement me
return self.w
def predictself Xtest: npndarray npndarray:
Use the trained weights to predict labels for test data points.
Parameters:
Xtest: a numpy array of shape N D containing testing data;
N examples with D dimensions
Returns:
predicted labels for the data in Xtest; a dimensional array of
length N where each element is an integer giving the predicted
class.
# TODO: implement me
pass
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
