Answered step by step
Verified Expert Solution
Question
1 Approved Answer
PLEASE HELP IN PYTHON. A perceptron is a binary linear classifier used in supervised learning which helps to classify the given input data. According to
PLEASE HELP IN PYTHON.
A perceptron is a binary linear classifier used in supervised learning which helps to classify the given input data. According to perceptron learning, the algorithm automatically learns the optimal weight coefficients. The input features are then multiplied with these weights to determine if a neuron fires or not. The perceptron receives multiple input signals, and if the sum of the input signals exceeds a certain threshold, it either outputs a signal or does not return an output. In the context of supervised learning and classification, the perceptron can then be used to predict the class of a sample.
In python, mody the given code which has sections missing below for the selfdriving section.
import numpy as np
import matplotlib.pyplot as plt
import PIL
from PIL import Image
#Let's first create a function that reads an image and returns its x binary matrix representation:
def getmatrixpath:
img Image.openpathconvertLA
matnpzeros
for x in range:
for y in range :
matyximg.getpixelx y
if matyx:
matyx
return mat
#Now we can read and print our selfdriving images:
leftgetmatrixImagenpng
pltimshowleft cmap"gray"
pltshow
straightgetmatrixImagenpng
pltimshowstraight cmap"gray"
pltshow
rightgetmatrixImagenpng
pltimshowright cmap"gray"
pltshow
#This is how one of our images looks like when binarized:
for i in range:
for j in range :
printintleftijend
print
#Output:
#Now using the code of the first point PERCEPTRON train a neural network that can "drive a car" based on our images:
#If presented with the image left, it has to respond If presented with the image straight, it has to respond And, finally, if presented with the image right, it has to respond
#INSTRUCTIONS: This perceptron network has two neurons and x inputs. The matrix of patterns P is of size x and not because you have to add, to each of the patterns, one more component for the bias The W matrix of weights is of size x neurons of parameters and has to be set randomly. The target matrix T is the following:
Tnparray
#You have to reshape the matrixes left, straight, and right to form the matrix P do not forget to add in the end to each reshaped matrix:
# Modify Your code here
Pshape
# Output:
# Set W randomly:
# Modify Your code here
Wshape
# Output:
# Train in a 'while' loop:
#Modify Your code here
# Print the error:
printsumsumE
# Output:
# Print the actual output of the network after training:
# Modify Your code here
# Output: array
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