Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Perceptron

Steps :

  1. Use prepare_data() method to prepare the inputs and labels. The prepare data accepts three parameters #@files - input file to read #@indices - tuple of indices to fetch from the file #@labls - dictionary of labels and their corresponding category value for encoding labels
	example usage : data1,label1 = prepare_data('train.data', indices = (0,80), labls = {"class-1": -1, "class-2": 1})
  1. Create an object of Perceptron class. The constructor recieves two parameters
	#@@ __init__ - params : {input_size,gamma}
	####@ input_size - input size
	####@ gamma - Coeficient of the l2 regularization default is 0 (no regularisation)
  1. Implement a binary Perceptron
	######### Prepare the data ###########
	data1,label1 = prepare_data('train.data',(0,80), labls = {"class-1": -1, "class-2": 1}) 
	Perceptron1 = Perceptron(4) 	############ Constructor with 4 input size ################
	Perceptron1.train(data1,label1,20)	############ Train the Perceptron ##############

	print(Perceptron1.data_matrix(data1,label1)) ############ View the data matrix ##############

	print(Perceptron1.activation(Perceptron1.predict(inputs = [1,2,3,4])))  ###### Prediction of new data point #####
  1. Multiple classes
	data1,label1 = prepare_data('train.data',(0,120), labls = {"class-1": 1, "class-2": -1, "class-3": -1})
	Perceptron1 = Perceptron(4) 			  ############ Constructor with 4 input size ################
	Perceptron1.train(data1,label1,20)	############ Train the Perceptron ##############

	print(Perceptron1.data_matrix(data1,label1)) ############ View the data matrix ##############
  1. Perceptron with l2 Regularisation
	data1,label1 = prepare_data('train.data',(0,120), labls = {"class-1": 1, "class-2": -1, "class-3": -1})
	Perceptron1 = Perceptron(4, gamma = 0.01) ############ Constructor with 4 input size ################
	Perceptron1.train(data1,label1,20)	  ############ Train the Perceptron ##############

	print(Perceptron1.data_matrix(data1,label1)) ############ View the data matrix ##############

About

Perceptron is a mathematical computational model for classifying only linearly separable data. Perceptron algorithm only works if the data is linearly separable.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages