{"action":"created","issue":{"url":"https://api.github.com/repos/fchollet/keras/issues/2051","repository_url":"https://api.github.com/repos/fchollet/keras","labels_url":"https://api.github.com/repos/fchollet/keras/issues/2051/labels{/name}","comments_url":"https://api.github.com/repos/fchollet/keras/issues/2051/comments","events_url":"https://api.github.com/repos/fchollet/keras/issues/2051/events","html_url":"https://github.com/fchollet/keras/issues/2051","id":143056401,"number":2051,"title":"Simple mlp with one hidden layer keeps predicting same number for all training examples","user":{"login":"asai95","id":18037290,"avatar_url":"https://avatars.githubusercontent.com/u/18037290?v=3","gravatar_id":"","url":"https://api.github.com/users/asai95","html_url":"https://github.com/asai95","followers_url":"https://api.github.com/users/asai95/followers","following_url":"https://api.github.com/users/asai95/following{/other_user}","gists_url":"https://api.github.com/users/asai95/gists{/gist_id}","starred_url":"https://api.github.com/users/asai95/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asai95/subscriptions","organizations_url":"https://api.github.com/users/asai95/orgs","repos_url":"https://api.github.com/users/asai95/repos","events_url":"https://api.github.com/users/asai95/events{/privacy}","received_events_url":"https://api.github.com/users/asai95/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2016-03-23T19:25:13Z","updated_at":"2016-03-24T15:21:45Z","closed_at":null,"body":"Hi, everyone! \r\nI've just started to learn keras and already have one serious problem. I'm trying to predict stock price using its previous values. The model I use is built on examlples from official site. This model minimizes its lost function and weights are changing, but when I'm trying to actualy predict prices using trainig examples, I'm getting an array with fixed number (well, it's changing a little, but insignificantly).\r\n\r\nHere's my code:\r\n```\r\nfrom keras.models import Sequential\r\nfrom keras.layers import Dense\r\nfrom keras.optimizers import SGD\r\nimport numpy\r\n\r\ndata = numpy.genfromtxt('data.csv', delimiter=';', skip_header=True, skip_footer=False)\r\n\r\nscale = numpy.max(data)\r\ndata /= scale\r\n\r\ny = data[:, :1]\r\nx = data[:, 1:]\r\n\r\nmodel = Sequential()\r\nmodel.add(Dense(7, input_dim=x.shape[1], init='uniform', activation='linear'))\r\nmodel.add(Dense(4, init='uniform', activation='tanh'))\r\nmodel.add(Dense(y.shape[1], init='uniform', activation='linear'))\r\n\r\nsgd = SGD(lr=0.06, decay=1e-6, momentum=0.5, nesterov=False)\r\nmodel.compile(loss='mean_squared_error', optimizer=sgd)\r\nmodel.fit(x, y, nb_epoch=2, batch_size=1, shuffle=False)\r\n\r\nprint(model.predict(x, batch_size=1)*scale)\r\n```\r\nAnd the output:\r\n```\r\nEpoch 1/2\r\n2451/2451 [==============================] - 2s - loss: 8.8777e-04     \r\nEpoch 2/2\r\n2451/2451 [==============================] - 2s - loss: 5.1640e-04     \r\n2451/2451 [==============================] - 1s     \r\n\r\n[[ 145.92594338]\r\n [ 145.92718066]\r\n [ 145.92615142]\r\n ..., \r\n [ 145.88787241]\r\n [ 145.88566064]\r\n [ 145.88658038]]\r\n```\r\nCan someone please explain what's wrong with this model. I understand that basic mlp is not a good predictor, especially with only previous values as input features, but this still seems wrong to me."},"comment":{"url":"https://api.github.com/repos/fchollet/keras/issues/comments/200883976","html_url":"https://github.com/fchollet/keras/issues/2051#issuecomment-200883976","issue_url":"https://api.github.com/repos/fchollet/keras/issues/2051","id":200883976,"user":{"login":"asai95","id":18037290,"avatar_url":"https://avatars.githubusercontent.com/u/18037290?v=3","gravatar_id":"","url":"https://api.github.com/users/asai95","html_url":"https://github.com/asai95","followers_url":"https://api.github.com/users/asai95/followers","following_url":"https://api.github.com/users/asai95/following{/other_user}","gists_url":"https://api.github.com/users/asai95/gists{/gist_id}","starred_url":"https://api.github.com/users/asai95/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asai95/subscriptions","organizations_url":"https://api.github.com/users/asai95/orgs","repos_url":"https://api.github.com/users/asai95/repos","events_url":"https://api.github.com/users/asai95/events{/privacy}","received_events_url":"https://api.github.com/users/asai95/received_events","type":"User","site_admin":false},"created_at":"2016-03-24T15:21:45Z","updated_at":"2016-03-24T15:21:45Z","body":"My bad. I forgot to point that predictions are multiplied by scaling factor (which is basically maximum in my dataset), but residual calculated as scaled targets - unscaled predictions.\r\nI also tried to run up to 100 epochs and got same result.\r\nMay be I should change batch size? I'm not quite understand how to choose it. Because each epoch takes about two seconds to learn on batch size = 1."}}