<jupyter_start><jupyter_text>How To Train A Neural Network In Python<jupyter_code># pip install neurolab
import neurolab as nl
import pylab as pl

input_data = [[0.3, 0.2], [0, 1.3], 
                  [1.4, 0.6], [0.5, 1.9]]
output = [[0], [1], [1], [1]]

pl.figure(0)
pl.scatter([x[0] for x in input_data], 
                   [x[1] for x in input_data]) 
pl.xlabel('X-axis')
pl.ylabel('Y-axis')
pl.show()<jupyter_output><empty_output><jupyter_text>To make it clearer, the figure below indicates the labels and the boundary we would like to see:<jupyter_code>from IPython.display import Image
Image("4-datapoints-with-outputs.png")<jupyter_output><empty_output><jupyter_text>As we can see here, we want to separate the points into two groups.  Let’s create a single-neuron network with 2 inputs (because we are dealing with 2-dimensional data):<jupyter_code># In the 1st argument, the length of the list “[[0, 2],[0, 2]]” is 2, 
# which indicates that there are 2 inputs. 
# Each item in this list has 2 elements. 
# 1st element indicates the minimum value that our input can take.
# 2nd element indicates the maximum value our input can take. 
# Value “1” in the 2nd argument indicates that there is a single neuron in this network.
perceptron = nl.net.newp([[0, 2],[0, 2]], 1)<jupyter_output><empty_output><jupyter_text>Let’s train this perceptron:<jupyter_code># The number of epochs indicates the number of training cycles. 
# “show” - refers to the printing frequency on the terminal.
# “lr” - refers to the learning rate of the algorithm. 
# Learning rate refers to the step size that’s taken to adjust 
# the parameters so that we move towards the end goal.
error = perceptron.train(input_data, output, epochs=50, show=15, lr=0.01)<jupyter_output>The goal of learning is reached<jupyter_text>Let’s plot the results:<jupyter_code>pl.figure(1)
pl.plot(error)
pl.xlabel('Number of epochs')
pl.ylabel('Training error')
pl.grid()
pl.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11353269133299544, 'fraction_numerical': 0.025342118601115054, 'mean_word_length': 4.656160458452722, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '226026', 'license': 'MIT', 'n_tokens_mistral': 705, 'n_tokens_neox': 666, 'n_words': 241, 'path': 'Neural_Network_Basic.ipynb', 'repo_name': 'Not-A-Builder/Basics-of-AI', 'size': '1973'}