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
Part : 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 and a bias The algorithm updates these parameters based on the training data.
Given a training set of samples dots, where and the perceptron makes predictions using the sign of the linear combination of the inputs and weights:
hatsign
where sign is a function that returns if and otherwise.
The perceptron updates its weights and bias using the perceptron learning rule:
hat
hat
Here, is the learning rate, a small positive scalar determining the step size of the update, is the true label, and hat is the predicted label.
Algorithm Steps
Initialization: Start with or small random values and
For each training example :
Compute the output hatsign
Update the weights and bias if hat :
wlarrw
blarrb
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
: Define the Perceptron Class: Create a class Perceptron with methods for initialization training fit and prediction pred ict
Theinit 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.
: Implement the Learning Rule
Within the fit method, implement the learning rule:
where:
hat
feature of the input vector
a feature based on how influential that feature is in causing the error.
: Testing and Evaluation
testing sets, using an split.
You might use the makeclassification or makeblobs 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.
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
