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, 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, 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:
#=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
#coef = used to avoid zero in log normalizations, example 0.0012345
#nn1c=5, nn2c=7, nn3c=5, nn4c=2 = number of neurons from the first to the fourth layer
#rate = learning rate
#epochs = number of epochs
#fa2c=5, fa3c=5, fa4c=0 = second to fourth layer activation functions
#for regression (quantitative forecasting) 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
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.PlotComparative(y_pred, y_resposta)
#Calculated and target comparative plot
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
File details
Details for the file tupa123-1.0.13.tar.gz
.
File metadata
- Download URL: tupa123-1.0.13.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8dfcc96c74508dada5b2717da9a923458b188ff739db2d4849ca822fc1a2af5a |
|
MD5 | 7fcb243ecc124cdc0fe133eb76032ba7 |
|
BLAKE2b-256 | f28a73df64fc43ac238c5d51c82101c6c17816f508ed8c2abd5c9e0003ba74c6 |