I'm trying to code a Multi-Layer Perceptron, but it seems I get it wrong when I'm trying to import data from csv file using genfromtxt function from numpy library.
from numpy import genfromtxt
dfX = genfromtxt('C:/Users/m15x/Desktop/UFABC/PDPD/inputX(editado_bits).csv', delimiter=',')
dfy = genfromtxt('C:/Users/m15x/Desktop/UFABC/PDPD/inputY(editado_bits).csv', delimiter=',')
X = dfX
y = dfy
print(X)
print(y)
# Whole Class with additions:
class Neural_Network(object):
def _init_(self):
# Define Hyperparameters
self.inputLayerSize = 26
self.outputLayerSize = 1
self.hiddenLayerSize = 10
# Weights (parameters)
self.W1 = np.random.randn(self.inputLayerSize, self.hiddenLayerSize)
self.W2 = np.random.randn(self.hiddenLayerSize, self.outputLayerSize)
And my X (124,1) and y (124,26) are the following arrays respectively:
[[ 1. 0. 1. ..., 1. 0. 0.]
[ 0. 1. 1. ..., 1. 0. 0.]
[ 0. 1. 1. ..., 1. 0. 0.]
...,
[ 0. 1. 1. ..., 1. 0. 0.]
[ 1. 0. 1. ..., 1. 0. 0.]
[ 1. 0. 1. ..., 1. 0. 0.]]
[ 0. 0. 1. 0. 1. 0. 1. 1. 0. 0. 0. 1. 1. 0. 0. 0. 0. 0.
0. 0. 1. 1. 0. 0. 0. 1. 0. 0. 1. 0. 0. 0. 1. 1. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 0. 1. 0. 0.
0. 0. 0. 0. 0. 0. 0. 1. 0. 1. 0. 0. 1. 0. 0. 0. 0. 0.
0. 1. 0. 1. 0. 1. 0. 0. 1. 1. 0. 0. 0. 1. 0. 1. 0. 1.
1. 1. 0. 0. 0. 1. 0. 0. 0. 0. 0. 0. 1. 0. 1. 0. 1. 0.
1. 0. 0. 0. 0. 1. 0. 1. 0. 1. 0. 1. 0. 0. 0. 0.]
And I get notified with:
Traceback (most recent call last):
File "C:/Users/m15x/PycharmProjects/Deep Learning/MLP_tinnitus_1.py", line 141, in <module>
T.train(X,y)
File "C:/Users/m15x/PycharmProjects/Deep Learning/MLP_tinnitus_1.py", line 134, in train
args=(X, y), options=options, callback=self.callbackF)
File "C:\Users\m15x\Anaconda3\lib\site-packages\scipy\optimize\_minimize.py", line 444, in minimize
return _minimize_bfgs(fun, x0, args, jac, callback, **options)
File "C:\Users\m15x\Anaconda3\lib\site-packages\scipy\optimize\optimize.py", line 913, in _minimize_bfgs
gfk = myfprime(x0)
File "C:\Users\m15x\Anaconda3\lib\site-packages\scipy\optimize\optimize.py", line 292, in function_wrapper
return function(*(wrapper_args + args))
File "C:\Users\m15x\Anaconda3\lib\site-packages\scipy\optimize\optimize.py", line 71, in derivative
self(x, *args)
File "C:\Users\m15x\Anaconda3\lib\site-packages\scipy\optimize\optimize.py", line 63, in _call_
fg = self.fun(x, *args)
File "C:/Users/m15x/PycharmProjects/Deep Learning/MLP_tinnitus_1.py", line 119, in costFunctionWrapper
grad = self.N.computeGradients(X, y)
File "C:/Users/m15x/PycharmProjects/Deep Learning/MLP_tinnitus_1.py", line 76, in computeGradients
dJdW1, dJdW2 = self.costFunctionPrime(X, y)
File "C:/Users/m15x/PycharmProjects/Deep Learning/MLP_tinnitus_1.py", line 56, in costFunctionPrime
delta2 = np.dot(delta3, self.W2.T) * self.sigmoidPrime(self.z2)
ValueError: shapes (124,124) and (1,10) not aligned: 124 (dim 1) != 1 (dim 0)
And mainly this error starts when I'm trying to train my code with the previous data.
def train(self, X, y):
# Make an internal variable for the callback function:
self.X = X
self.y = y
# Make empty list to store costs:
self.J = []
params0 = self.N.getParams()
options = {'maxiter': 10000, 'disp': True}
_res = optimize.minimize(self.costFunctionWrapper, params0, jac=True, method='BFGS', \
args=(X, y), options=options, callback=self.callbackF)
self.N.setParams(_res.x)
self.optimizationResults = _res
I know my array from X and y doens't fit, but I don't know some usable function that I can apply to treat the data for the variable y, which is fed by the (124,1) shape data csv file ('C:/Users/m15x/Desktop/UFABC/PDPD/inputY(editado_bits).csv') and my X variable is fed by a (124,26) shape csv file ('C:/Users/m15x/Desktop/UFABC/PDPD/inputX(editado_bits).csv'). It seems my data imported using genfromtxt function doesn't seem appropriate.