Question: Homework 2 Part 1 : Perceptron from Scratch assignment, you will have a working perceptron model that can classify linearly separable datasets. Background inputs and

Homework 2
Part 1: Perceptron from Scratch
assignment, you will have a working perceptron model that can classify linearly separable datasets.
Background
inputs and "fires" or "activates" if the sum exceeds a threshold.
The perceptron decision boundary is defined by a weight vector w and a bias b. The algorithm updates these parameters based on the training data.
Given a training set of n samples (x1,y1),(x2,y2),dots,(xn,yn), where xiinRd and yiin{-1,1}, the perceptron makes predictions using the sign of the linear combination of the inputs and weights:
hat(y)(x)=sign(w*x+b)
where sign(z) is a function that returns 1 if z0 and -1 otherwise.
The perceptron updates its weights w and bias b using the perceptron learning rule:
wnextstep=w+(y-hat(y))x
bnextstep=b+(y-hat(y))
Here, is the learning rate, a small positive scalar determining the step size of the update, y is the true label, and hat(y) is the predicted label.
Algorithm Steps
Initialization: Start with w=0 or small random values and b=0.
For each training example (xi,yi) :
Compute the output hat(y)(xi)=sign(w*xi+b).
Update the weights and bias if hat(y)yi :
wlarrw+(yi-(hat(y))(xi))xi
blarrb+(yi-(hat(y))(xi))
Repeat: Go through the training set multiple times, until the algorithm converges (no misclassifications) or a predefined number of iterations is reached.
The perceptron algorithm is guaranteed to converge on linearly separable data sets, but it does not converge if the data is not linearly separable.
Your Implementation
1.1: Define the Perceptron Class: Create a class Perceptron with methods for initialization (_), training (fit), and prediction (pred ict).
The__init__ method should initialize the weights and the threshold.
The fit method should implement the perceptron learning algorithm, adjusting the weights based on the inputs and the target output.
The predict method should take inputs and produce the perceptron's output for those inputs.
1.2: Implement the Learning Rule
Within the fit method, implement the learning rule:
wi=wi+wi
where:
wi=(y-hat(y))xi
ith feature of the input vector x.
a feature based on how influential that feature is in causing the error.
1.3: Testing and Evaluation
testing sets, using an 8020 split.
You might use the make_classification or make_blobs functions from the sklearn. datasets module to generate this dataset.
Plot your dataset to visualize the distribution of the classes. Create a scatterplot, with axes representing the two features and different colors for each class.
Evaluate Your Model: After training, evaluate the accuracy of your model on the testing set. Calculate the proportion of correctly predicted instances to demonstrate the efficacy of your perceptron.
 Homework 2 Part 1: Perceptron from Scratch assignment, you will have

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!