A feed forward neural network with Python

Spread the word!

First of all, prepare to execute the python script by installing the proper libraries in the Anaconda terminal:

If you have problems to install tensorflow, try to do it with the following commands (according to anaconda.com)

I commented the next python code, taken from the book of Sandro Skansi “Introduction to Deep Learning. From Logical Calculus to Artificial Intelligence” (pag. 103, 104, 105).

The scenario is that we have a webshop selling books and other stuff, and we want to know whether a customer will abandon a shopping basket at checkout. This is why we are making a neural network to predict it.

It takes data.csv for the training and test phase and then applies the resulting algorithm to predict the new data of new_data.csv, which contains the same columns of data.csv but without the target value. All neurons will be having the logistic activation functions. It will show the prediction accuracy in the terminal.

This is data.csv:

includes_a_book,purchase_after_21,total,user_action
1,1,13.43,1
1,0,23.45,1
0,0,45.56,0
1,1,56.43,0
1,0,44.44,0
1,1,667.65,1
1,0,56.66,0
0,1,43.44,1
0,0,4.98,1
1,0,43.33,0

This is new_data.csv

includes_a_book,purchase_after_21,total
1,0,73.75
0,0,64.97
1,0,3.78
0,0,60

Main code, called ffnn.py:

Execute if by typing in the Anaconda terminal:

Screenshot of result with 150 epochs:
Unbenannt

Screenshot of result with 300 epochs:
Unbenannt2

The results are expected to vary since the input training samples are taken randomly.

Be the first to comment

Leave a Reply

Your email address will not be published.


*