Sitemap
anonymous

anonymous

Programming MP neuron

2 min readApr 16, 2020

--

step 1:

I am importing sample data using sklearn.datasets . Here I am importing breast cancer data . Our job is to tell whether the given sample has benign or malignant cancer.

step 2:

Next step is to divide the data set to two parts training set and testing set. I am using sklearn.model_selection to divide the data set to test and train set.
I can choose the ratio of test split to train split using test_size = ‘ratio’ also I can keep the ratio of benign and malignant ratio in test and train same as original data set using stratify = ‘ class label’ . I can keep the split same every time I run it using random_state = 1

step 3:

I have real world inputs but MP neuron only takes boolean inputs . So change to inputs to boolean form using pandas cut we want two bins and labels equal to 0 and 1 , this will divide the every feature name values to either 0 or 1 taking some value between them to compare and decide which label will it take. After converting the data to 0’s and 1’s now make the test data and train data to numpy arrays using ‘values’.

Get anonymous’s stories in your inbox

Join Medium for free to get updates from this writer.

step 4:

Now coming to algorithm ,

program to find the efficiency of the MP neuron

the output would be,

for b = 28 the efficiency is maximum i.e 84%

Now since I got b = 28 for train data , now I check this for test data and find the efficiency. I am using sklearn.accuracy_score for finding the accuracy directly.

Press enter or click to view image in full size
Accuracy is 78% for b = 28

step 5:

To make the MP neuron as template such that it can be used for any data sets ,I am creating class of MP neuron.

Press enter or click to view image in full size
MP neuron class that calculates best thresholding factor and corresponding efficiency

--

--