Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The fit function def fit(self, X, y, pocket = True, epochs = 100): if(self.degree > 1): X = z_transform(X, degree=self.degree) let n and d be

The fit function

def fit(self, X, y, pocket = True, epochs = 100): if(self.degree > 1): X = z_transform(X, degree=self.degree) let n and d be the row count and column count of X Insert the bias column into X // use np.insert Init self.w to an (d+1) x 1 matrix of all 0. if not pocket: while the last epoch has made at lease one change to self.w for i in range(n): if X[i] is misclassifed: //use np.sign(matrix row @ self.w) update self.w using the PLA algorithm else: while last epoch has changed self.w and epochs > 0: epochs -= 1 for i in range(n): if X[i] is misclassifed: //use np.sign(matrix row @ self.w) update self.w using the PLA algorithm use self.w to calc total misclassified count //use @, np.sign, np.sum save self.w as best_w, if total misclassified count becomes smaller self.w = best_w

return self.w

The predict() function def predict(self, X): if(self.degree > 1): X = MyUtils.z_transform(X, degree = self.degree) Add the bias column into X // use np.insert return the vector of predicted labels //use @ for X and self.w, np.sign

The predict() function def error(self, X, y): if(self.degree > 1): X = MyUtils.z_transform(X, degree = self.degree) Add the bias column into X // use np.insert //use @ for X and self.w, and np.sign Calc the vector of predicted labels. Save the result in y_pred Count the mismatched b/w y_pred and y //use np.sum

return the above count

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions

Question

What are the objectives of Human resource planning ?

Answered: 1 week ago

Question

Explain the process of Human Resource Planning.

Answered: 1 week ago