Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

We Developed A Python Code To Train A Perceptron For A Set Of Given Data Points. See The File Below: Click To Open D The

We Developed A Python Code To Train A Perceptron For A Set Of Given Data Points. See The File Below: Click To Open D The Total Number Of Samples Is The Number Of Attributes Is And The Final Classification Accuracy Is % NOTE: Enter All Your Answers In Numbers. Import Numpy As Np Import Matplotlib.Pyplot As Plt + Class To Create A Neural Network With Single

single neuron class NeuralNetwork(object): det _init__(self, num_params 3) : + Using seed to make sure it'll generate same weights in every run np. random.seed (1) 3xl Weight matrix selt.weight_matrix 2 np.random.random((num_params+1, 1)) - 1 #random weights between-1 and self.1_rate hard_limiter as activation fuention def hard_limiter(self,x): outs-np.zeros(x.shape) outs[x>01=1 return outs I forward propagation det forward propagation(self

inputs): outs-np.dot (inputs, self.weight_matrix) return self.hard_limiter(outs) training the neural network. det train(self, train_inputs, train outputs, num train iterations 1000): Number of iterations we want to perform for this set of input. for iteration in range(num_train iterations) updating the perceptron base on the misclassified examples for in rangetrain inputs, shape) pred 1 = selt.pred(train inputs 1,1)) i pred_itstrain outputs) output selt, forward propagation

(train_inputsi.) calculate the error in the output. error train outputatil output adjustint - selt.l_rate error train_inputstil Adjust the weight mateix selt.weight matrix, adjustment #predicting the classes of new data points det pred(self, inputs): preda-self.forward propagation inputs) return preds teatures-np.array), 0.5). 12.5 print features 1.51. 10.5.2.5.-1), 11.1.11. 1-2,-2. Tabelt np.array([0,0,1,1,1)) print labels) classes 10,11 0.51 12.5 1.5 1.51 10.5 1.5-11 .. 2.1.11 TOOL biasap.onest features shapero),1)) Yexpanding the feature space by adding the bias vector

printiias printias.shape) features sp.append(bias, features axis-1) printteatures printteatures.shape 1 111.1 11.1 11.1 11.11 5.13 3. 225 0.5 3. 9.35 15 1.51 1.5 1 neural network - NeuralNetwork() print { \"Random weights at the start of training) print (neural network, weight_matrix) Random weights at the start of training 0.6519418) 10.71739732) 0.41924576) 0.020861331 en Betreuraltetvork (3) prant Randoe weights at the start of training') beist eerst

ervark weight_matrix) searal network.trainteatures, labels, 10) pant et atter training at neural netwoight matrix) est the neural network with training data points brint Testing network on training data points print (neural network.prediteatures) Randon weights at the start of training 11-0.680213091 -0.07547043) 0.22324879) 1-0.09532928) New weights after training 115.)1975691) 1-2557547043) 10.72324879) I -1.0953292011 Testing network on training data pointe-> TO) 10. 11.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions

Question

What does equilibrium price represent?

Answered: 1 week ago