Skip to main content

fully connected neural network with four layers

Project description

Fully connected four-layer neural network
Solves a huge number of cases, classification and regression
The following sequence explains how to use with the help of two example files.
The first file contains the learning process, where the neural network finds its weights
The second file demonstrates the network's ability to make predictions on new, unseen data that is not part of the training set

#-----Files without comments:---------------------------------------

#-----FILE TO MACHINE LEARNING

import tupa123 as tu

X = tu.ExcelMatrix('ALETAS.xlsm', 'Plan1', Lineini=2, Columini=1, columnquantity=5, linesquantity=300)
y = tu.ExcelMatrix('ALETAS.xlsm', 'Plan1', Lineini=2, Columini=6, columnquantity=2, linesquantity=300)

model = tu.nnet4(norma=5, coef=0, nn1c=5, nn2c=7, nn3c=5, nn4c=2, rate=0.01, epochs=2000, fa2c=5, fa3c=5, fa4c=0)
model.Fit_ADAM(X, y)
model.Plotconv()

input('end')

#-----FILE TO APPLICATION OF MACHINE LEARNING

import tupa123 as tu

model = tu.nnet4(norma=5, coef=0, normout=1, nn1c=5, nn2c=7, nn3c=5, nn4c=2, fa2c=5, fa3c=5, fa4c=0)
X_new = tu.ExcelMatrix('ALETAS.xlsm', 'Plan1', Lineini=2, Columini=1, columnquantity=5, linesquantity=1000)
y_resposta = tu.ExcelMatrix('ALETAS.xlsm', 'Plan1', Lineini=2, Columini=6, columnquantity=2, linesquantity=1000)
y_pred = model.Predict(X_new)

tu.Statistics(y_pred, y_resposta)
tu.PlotCorrelation(y_pred, y_resposta)
tu.PlotComparative(y_pred, y_resposta)
input('end')

#------Commented file:------------------------------------------

#-----MACHINE LEARNING

import tupa123 as tu
#import the library

X = tu.ExcelMatrix('ALETAS.xlsm', 'Plan1', Lineini=2, Columini=1, columnquantity=5, linesquantity=300)
y = tu.ExcelMatrix('ALETAS.xlsm', 'Plan1', Lineini=2, Columini=6, columnquantity=2, linesquantity=300)
#learning data
#The data can come from any source, but the ExcelMatrix function allows a practical interaction with Excel
#ExcelMatrix = collect data from excel, the spreadsheet needs to be in the same folder as the python file
#'ALETAS.xlsm' = example name of the excel file / 'Sheet1' = example name of the tab where the data are
#Lineini=2, Columini=1 = example initial row and column of data
#linesquantity = number of lines of learning data
#X = regression input data / y = data to be predicted

model = tu.nnet4(norma=5, coef=0, normout=1, nn1c=5, nn2c=7, nn3c=5, nn4c=2, rate=0.01, epochs=2000, fa2c=5, fa3c=5, fa4c=0)
#creates the Neural Network model
#norma = type of data normalization: (default=2)
#=-1, standardization
#=0, do anything
#=1, between 0 and 1
#=2, between -1 and 1
#=3, log(x+coef)
#=4, log(x+coef) between 0 and 1
#=5, log(x+coef) between -1 and 1
#=6, log(x+coef) and standardization
#coef = used to avoid zero in log normalizations, example 0.0012345 (default=0)
#normout = if 1 normalizes the output (default=1)
#nn1c=5, nn2c=7, nn3c=5, nn4c=2 = number of neurons from the first to the fourth layer (default=1,5,5,1)
#rate = learning rate (default=0.01)
#epochs = number of epochs (default=1000)
#fa2c=5, fa3c=5, fa4c=0 = second to fourth layer activation functions (default=5,5,0)
#for regression the fourth layer is recommended as linear = 0
#Activation functions:
#=0 linear
#=1 Sigmoide
#=2 softpluss
#=3 gaussinana
#=4 ReLU
#=5 tanh
#=6 LReLU
#=7 arctan
#=8 exp
#=9 seno
#=10 swish
#=11 selu
#=12 logsigmoide
#=13 X2
#=14 X
3
#=15 Symmetric Rectified Linear

model.Fit_ADAM(X, y)
#machine learning
#model.Fit_ADAM(X, y) = single batch interpolation of all learning data, with ADAM accelerator
#model.Fit_STOC(X, y) = case-by-case interpolation, stochastic gradient descent

model.Plotconv()
#Plot the convergence process

input('End')

#-----APPLICATION OF MACHINE LEARNING

import tupa123 as tu

model = tu.nnet4(norma=5, coef=0, nn1c=5, nn2c=7, nn3c=5, nn4c=2, fa2c=5, fa3c=5, fa4c=0)
#application file must be in the same folder as the learning file
#where some .txt files were generated with the neural network settings
#neural network must have the same configuration that was used in the learning phase

X_new = tu.ExcelMatrix('ALETAS.xlsm', 'Plan1', Lineini=2, Columini=1, columnquantity=5, linesquantity=1000)
#variables to be predicted

y_resposta = tu.ExcelMatrix('ALETAS.xlsm', 'Plan1', Lineini=2, Columini=6, columnquantity=2, linesquantity=1000)
#right answer to compare, to evaluate neural network performance

y_pred = model.Predict(X_new)
#prediction, neural network result

tu.Statistics(y_pred, y_resposta)
#Statistical evaluation of the results
#It does some basic statistics: mean difference, standard deviation and correlation coefficient between predicted and target variable

tu.PlotCorrelation(y_pred, y_resposta)
#Calculated and target correlation plot

tu.PlotCorrelation2(y_pred, y_resposta)
#Calculated and target correlation plot with standard deviation lines

tu.PlotComparative(y_pred, y_resposta)
#Calculated and target comparative plot

tu.PlotComparative2(y_pred, y_resposta)
#Calculated and target comparative plot

tu.PlotComparative3(y_pred, y_resposta)
#Calculated and target comparative plot with standard deviation areas

tu.PlotDispe(y_pred, y_resposta)
#Error dispersion

tu.PlotDispe2(y_pred, y_resposta)
#Error dispersion with error proportion

tu.PlotHisto(y_pred, y_resposta)
#Percentage error histogram

input('end')

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tupa123-1.2.10.tar.gz (11.8 kB view details)

Uploaded Source

File details

Details for the file tupa123-1.2.10.tar.gz.

File metadata

  • Download URL: tupa123-1.2.10.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for tupa123-1.2.10.tar.gz
Algorithm Hash digest
SHA256 974a8f9a540dcc5c861d339e03e3565fa650c19793f96a6685c2e93c8e9323e5
MD5 c264647ae47f48b114004c76bdbc5a66
BLAKE2b-256 db756f6154eb30e068655b373fb69594b9fa5f3a46be1a0633e6a68456ddc224

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page