Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dimension Error on Training the NN #19

Open
jonmilson opened this issue Nov 18, 2016 · 1 comment
Open

Dimension Error on Training the NN #19

jonmilson opened this issue Nov 18, 2016 · 1 comment

Comments

@jonmilson
Copy link

Hi,

I tried to implement the same code, but changed the layers as shown:

    self.inputLayerSize = 3 
    self.outputLayerSize = 5 
    self.hiddenLayerSize = 5

This is because the data set shape is:
X = (4162, 3)
Y = (4162,)

However, after executing T.train(X, Y), I get the following error:


ValueError Traceback (most recent call last)
in ()
----> 1 T.train(X, Y)

in train(self, X, y)
26
27 options = {'maxiter': 200, 'disp' : True}
---> 28 _res = optimize.minimize(self.costFunctionWrapper, params0, jac=True, method='BFGS', args=(X, y), options=options, callback=self.callbackF)
29
30 self.N.setParams(_res.x)

//anaconda/lib/python2.7/site-packages/scipy/optimize/_minimize.pyc in minimize(fun, x0, args, method, jac, hess, hessp, bounds, constraints, tol, callback, options)
439 return _minimize_cg(fun, x0, args, jac, callback, **options)
440 elif meth == 'bfgs':
--> 441 return _minimize_bfgs(fun, x0, args, jac, callback, **options)
442 elif meth == 'newton-cg':
443 return _minimize_newtoncg(fun, x0, args, jac, hess, hessp, callback,

//anaconda/lib/python2.7/site-packages/scipy/optimize/optimize.pyc in _minimize_bfgs(fun, x0, args, jac, callback, gtol, norm, eps, maxiter, disp, return_all, **unknown_options)
845 else:
846 grad_calls, myfprime = wrap_function(fprime, args)
--> 847 gfk = myfprime(x0)
848 k = 0
849 N = len(x0)

//anaconda/lib/python2.7/site-packages/scipy/optimize/optimize.pyc in function_wrapper(*wrapper_args)
287 def function_wrapper(wrapper_args):
288 ncalls[0] += 1
--> 289 return function(
(wrapper_args + args))
290
291 return ncalls, function_wrapper

//anaconda/lib/python2.7/site-packages/scipy/optimize/optimize.pyc in derivative(self, x, *args)
69 return self.jac
70 else:
---> 71 self(x, *args)
72 return self.jac
73

//anaconda/lib/python2.7/site-packages/scipy/optimize/optimize.pyc in call(self, x, *args)
61 def call(self, x, *args):
62 self.x = numpy.asarray(x).copy()
---> 63 fg = self.fun(x, *args)
64 self.jac = fg[1]
65 return fg[0]

in costFunctionWrapper(self, params, X, y)
10 def costFunctionWrapper(self, params, X, y):
11 self.N.setParams(params)
---> 12 cost = self.N.costFunction(X, y)
13 grad = self.N.computeGradients(X,y)
14

in costFunction(self, X, y)
29 #Compute cost for given X,y, use weights already stored in class.
30 self.yHat = self.forward(X)
---> 31 J = 0.5*np.sum((y-self.yHat)**2)
32 return J
33

ValueError: operands could not be broadcast together with shapes (4162,) (4162,5)

Would appreciate the help!

@AnuragNagare
Copy link

I have added a new file named "Updated Part 7 Overfitting, Testing, and Regularization" in which i have updated the cost function for this problem run the code and let me know

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants