Artificial Neural Network from Scratch Using Python

Perceptron in Action

Joel Raymond Day
CodeX

--

Photo by Google DeepMind on Unsplash

Here I create a neural network from scratch that uses age, fitness, and diet to predict a health score from 1–10. As it turns out the training data was made up — by me —so although the features are arbitrary and the output is meaningless, this network DOES kick butt at answering, ‘How does a neural network work?’

This network has 3 input neurons and 1 output neuron. There should be 1 input neuron for each independent feature and they all require scaling - a min-max scaler (linear) is used.

import numpy as np # for math
import pandas as pd # for data storage
import random # for weight and bias generation
import time # to record training time
import matplotlib.pyplot as plt # visuals
# independent variables (requires scaling)
age = np.array([60, 63, 17, 35, 90, 10])
exercise = np.array([8, 2, 7, 4, 1, 9])
diet = np.array([7, 2, 7, 5, 1, 7])

# min-max scaling for independent features
x1 = (age - 0) / (101 - 0)
x2 = (exercise - 0) / (11 - 0)
x3 = (diet - 0) / (11 - 0)

# dependent variable (does not need to be scaled)
y = np.array([7, 3, 9, 6, 1, 10])

--

--