May-04-2020, 10:24 PM
Hello, I am new in python. Need help with neural network code.
I have data in .xlxs file. Dimensions 7027x65.
This is data file
Data file
First of all I calculate 20% of my data for training my neural network, and set output training array
For prediction I am using other 80% of data
This all the code:
By running the code I'm get this error:
![[Image: view?usp=sharing]](https://drive.google.com/file/d/1-yWGMQFhSSGIitqRNXoqGhmIliv5prse/view?usp=sharing)
How to fix that? Thanks for your help.
I have data in .xlxs file. Dimensions 7027x65.
This is data file
Data file
First of all I calculate 20% of my data for training my neural network, and set output training array
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
import pandas as pd import numpy as np dataset = pd.read_excel( "C:\\Users\\tigra\\Desktop\\1year.xlsx" ) # nuskaitymas exel failo # Calculate 20% dydis = dataset.shape print ( 'Masyvo dimension: ' ,dydis) row = round ((dydis[ 0 ] * (dydis[ 1 ] - 1 )) * 0.2 / (dydis[ 0 ])) Training_array = dataset.iloc[:,:row] Training_array_dimensions = Training_array.shape print ( 'Masyvo dimension: ' ,Training_array_dimensions) # input data inputs = Training_array outputs = np.array([ 100 ]) |
1 2 3 4 |
# create two new examples to predict example = dataset.iloc[:,row:] example_dimension = example.shape print ( 'Masyvo dimension: ' ,example_dimension) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# create NeuralNetwork class class NeuralNetwork: # intialize variables in class def __init__( self , inputs, outputs): self .inputs = inputs self .outputs = outputs # initialize weights as .50 for simplicity self .weights = np.full([ 7027 , 1 ], . 50 ) self .error_history = [] self .epoch_list = [] #activation function ==> S(x) = 1/1+e^(-x) def sigmoid( self , x, deriv = False ): if deriv = = True : return x * ( 1 - x) return 1 / ( 1 + np.exp( - x)) # data will flow through the neural network. def feed_forward( self ): self .hidden = self .sigmoid(np.dot( self .inputs, self .weights)) # going backwards through the network to update weights def backpropagation( self ): self .error = self .outputs - self .hidden delta = self .error * self .sigmoid( self .hidden, deriv = True ) self .weights + = np.dot( self .inputs.T, delta) # train the neural net for 25,000 iterations def train( self , epochs = 25000 ): for epoch in range (epochs): # flow forward and produce an output self .feed_forward() # go back though the network to make corrections based on the output self .backpropagation() # keep track of the error history over each epoch self .error_history.append(np.average(np. abs ( self .error))) self .epoch_list.append(epoch) # function to predict output on new and unseen input data def predict( self , new_input): prediction = self .sigmoid(np.dot(new_input, self .weights)) return prediction # create neural network NN = NeuralNetwork(inputs, outputs) # train neural network NN.train() # print the predictions for both examples print (NN.predict(example), ' - Correct: ' ) |
How to fix that? Thanks for your help.