Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Linear Regression model import numpy as np class Linear ( object ) : def _ _ init _ _

"""
Linear Regression model
"""
import numpy as np
class Linear(object):
def __init__(self, n_class: int, lr: float, epochs: int, weight_decay: float):
"""Initialize a new classifier.
Parameters:
n_class: 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.n_class = n_class
self.weight_decay = weight_decay
def train(self, X_train: np.ndarray, y_train: np.ndarray, weights: np.ndarray)-> np.ndarray:
"""Train the classifier.
Use the linear regression update rule as introduced in the Lecture.
Parameters:
X_train: a number array of shape (N, D) containing training data;
N examples with D dimensions
y_train: a numpy array of shape (N,) containing training labels
"""
N, D = X_train.shape
self.w = weights
# TODO: implement me
return self.w
def predict(self, X_test: np.ndarray)-> np.ndarray:
"""Use the trained weights to predict labels for test data points.
Parameters:
X_test: a numpy array of shape (N, D) containing testing data;
N examples with D dimensions
Returns:
predicted labels for the data in X_test; a 1-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

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

More Books

Students also viewed these Databases questions

Question

What might SKI do to reduce its cash without harming operations?

Answered: 1 week ago

Question

Evaluate the integral. x* + 3x? + 1 .2 dx .5 x* + 5x + 5x .3

Answered: 1 week ago

Question

7. List behaviors to improve effective leadership in meetings

Answered: 1 week ago

Question

6. Explain the six-step group decision process

Answered: 1 week ago