Answered step by step
Verified Expert Solution
Question
1 Approved Answer
4 . Programming a perceptron: Consider a classification problem of two continuous input variables and a binary class variable. Apply perceptron weight training algorithm to
Programming a perceptron: Consider a classification problem of two continuous input variables and a binary class variable. Apply perceptron weight training algorithm to find a line that seperates the two classes.
Choose a learning rate
Stat with initial weights for each variable and a bias term which are small numbers: uniformly distributed between and
Iterate until accuracy is for P or accuracy reachs a reasonable value for P
At each step
Update weights and bias
Monitor accuracy and the weights and bias
When stopped: monitor the final weights and accuracy
Solve the problem for the two datasets P and P P isa linearly seperable data whereas P cannot be perectly separated by a single perceptron.
Each problem is solved by a different program in Python
Input Generation
Generate data points of two continuous inputs uniformly distributed between and
Make s scatter plot of your data
These are the input features of two continuous variable used in both P and P
P: A Linearly Seperable Dataset
Labesl the data with two lnearly seperable classes
Choose a line in dimensional input space specified by ww and w the three weigths of the perceptron
Such as L: wx wx w
Such as L: xx
Where x and x are input features and ww and w are weigths to be learned by the perceptron
Here as you set the line such that
Above lhis line if L the output class is yes or
f L the class is not buy or
For all input of two features between and
Apply the above formula to generate a label
So at the end of labeling approximately of your date is labeled as class and the other is of class
Then implement a percvepron training alorithm in Python
Start with initial weights
Choose a learning rate
In each eopch
Pass over all data point
and make a littel update of the weights
Aster several epochs
plot the labeled daa together with the learned line
Monitor the accuracy rate as well
Note Since the problem is linearly seperable by the line whose equation you know
The final accuracy shoud be
You know the line as the generator of he datga.
Let the perceptrn learn it: learn the weigths ww and w
P A dataset that is not linearly seperable
In P ht eline you set say x x perfectlyseperates the two classes
Say above it is class and below it as class
Now lst us generatre classes assign labels to the say inputs so as to generate a data set that is not linearly seperable.
Think of two additional lines just units above and below the seperating line.
Say LU: x x and
LL: x x
How to label an nonseperable class
Pass over all data
If LU is satisfied x x Label as class
els if LL is satisfied x x Label as class
else data is in beween LU and LU
generate a ranom number between and say r
if r label as class otherwise label as class
This is how the inputs are labeled as a not linearly seperable data
Tht is a line a single perceptron cannot seperarte with accuracy
Make a sctter plot of the data includeing the labeled classes
Appy the perceptron algorithm you depelop to this data
After several s or s of eqochs
Monitor the accuracy rate or the error rate
Make scatter plot of the data as well as the lerend line
Make a comperison with P
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started