problem of entry format for a simple model in Keras2019 Community Moderator ElectionKeras : problem in fitting modelIndex error in simple keras modelKeras LSTM: use weights from Keras model to replicate predictions using numpyKeras Loss Function for Multidimensional Regression ProblemSimple prediction with KerasValueError: Error when checking target: expected dense_2 to have shape (1,) but got array with shape (0,)Keras input shape errorValue error in Merging two different models in kerasSteps taking too long to completeAutoencoder Dimensionality Error
What is the meaning of "of trouble" in the following sentence?
Is every set a filtered colimit of finite sets?
How would photo IDs work for shapeshifters?
Is there a name of the flying bionic bird?
How could a lack of term limits lead to a "dictatorship?"
Manga about a female worker who got dragged into another world together with this high school girl and she was just told she's not needed anymore
What happens when a metallic dragon and a chromatic dragon mate?
Could a US political party gain complete control over the government by removing checks & balances?
aging parents with no investments
I see my dog run
What is the command to reset a PC without deleting any files
Filling an area between two curves
Does a dangling wire really electrocute me if I'm standing in water?
Lied on resume at previous job
Patience, young "Padovan"
Ideas for 3rd eye abilities
How to move the player while also allowing forces to affect it
Crop image to path created in TikZ?
Why airport relocation isn't done gradually?
How to manage monthly salary
Why is the design of haulage companies so “special”?
Landlord wants to switch my lease to a "Land contract" to "get back at the city"
Can the Produce Flame cantrip be used to grapple, or as an unarmed strike, in the right circumstances?
What to wear for invited talk in Canada
problem of entry format for a simple model in Keras
2019 Community Moderator ElectionKeras : problem in fitting modelIndex error in simple keras modelKeras LSTM: use weights from Keras model to replicate predictions using numpyKeras Loss Function for Multidimensional Regression ProblemSimple prediction with KerasValueError: Error when checking target: expected dense_2 to have shape (1,) but got array with shape (0,)Keras input shape errorValue error in Merging two different models in kerasSteps taking too long to completeAutoencoder Dimensionality Error
$begingroup$
I apologize if this question is too elementary for this site. I am new in learning Keras and Tensorflow and I have the following type/shape problem on which I have already wasted too much time.
I entered this code (found on the web) to construct a keras model using sequential()
from keras.models import Sequential
from keras.layers import Dense, Activation
model = Sequential()
model.add(Dense(32, activation='relu', input_dim=100))
model.add(Dense(1, activation='sigmoid'))
model.compile(optimizer='rmsprop',
loss='binary_crossentropy',
metrics=['accuracy'])
I then want to try the function model.evaluate(). But I can't find in the documentation nor in my trials and errors under what format the entry of evaluate should be. Among many other things, I have tried:
import numpy as np
model.evaluate(np.random.random((100,)))
but I get a long error message ending in
ValueError: Error when checking input: expected dense_1_input to have shape (100,) but got array with shape (1,)
Anyone has an idea what is happening here? Just a simple line of code
creating a dummy entry that my model could evaluate() would unstuck me, I think.
machine-learning python keras tensorflow
$endgroup$
add a comment |
$begingroup$
I apologize if this question is too elementary for this site. I am new in learning Keras and Tensorflow and I have the following type/shape problem on which I have already wasted too much time.
I entered this code (found on the web) to construct a keras model using sequential()
from keras.models import Sequential
from keras.layers import Dense, Activation
model = Sequential()
model.add(Dense(32, activation='relu', input_dim=100))
model.add(Dense(1, activation='sigmoid'))
model.compile(optimizer='rmsprop',
loss='binary_crossentropy',
metrics=['accuracy'])
I then want to try the function model.evaluate(). But I can't find in the documentation nor in my trials and errors under what format the entry of evaluate should be. Among many other things, I have tried:
import numpy as np
model.evaluate(np.random.random((100,)))
but I get a long error message ending in
ValueError: Error when checking input: expected dense_1_input to have shape (100,) but got array with shape (1,)
Anyone has an idea what is happening here? Just a simple line of code
creating a dummy entry that my model could evaluate() would unstuck me, I think.
machine-learning python keras tensorflow
$endgroup$
$begingroup$
Trymodel.evaluate(np.random.random((100, 3)))
$endgroup$
– Vaalizaadeh
Mar 30 at 19:41
add a comment |
$begingroup$
I apologize if this question is too elementary for this site. I am new in learning Keras and Tensorflow and I have the following type/shape problem on which I have already wasted too much time.
I entered this code (found on the web) to construct a keras model using sequential()
from keras.models import Sequential
from keras.layers import Dense, Activation
model = Sequential()
model.add(Dense(32, activation='relu', input_dim=100))
model.add(Dense(1, activation='sigmoid'))
model.compile(optimizer='rmsprop',
loss='binary_crossentropy',
metrics=['accuracy'])
I then want to try the function model.evaluate(). But I can't find in the documentation nor in my trials and errors under what format the entry of evaluate should be. Among many other things, I have tried:
import numpy as np
model.evaluate(np.random.random((100,)))
but I get a long error message ending in
ValueError: Error when checking input: expected dense_1_input to have shape (100,) but got array with shape (1,)
Anyone has an idea what is happening here? Just a simple line of code
creating a dummy entry that my model could evaluate() would unstuck me, I think.
machine-learning python keras tensorflow
$endgroup$
I apologize if this question is too elementary for this site. I am new in learning Keras and Tensorflow and I have the following type/shape problem on which I have already wasted too much time.
I entered this code (found on the web) to construct a keras model using sequential()
from keras.models import Sequential
from keras.layers import Dense, Activation
model = Sequential()
model.add(Dense(32, activation='relu', input_dim=100))
model.add(Dense(1, activation='sigmoid'))
model.compile(optimizer='rmsprop',
loss='binary_crossentropy',
metrics=['accuracy'])
I then want to try the function model.evaluate(). But I can't find in the documentation nor in my trials and errors under what format the entry of evaluate should be. Among many other things, I have tried:
import numpy as np
model.evaluate(np.random.random((100,)))
but I get a long error message ending in
ValueError: Error when checking input: expected dense_1_input to have shape (100,) but got array with shape (1,)
Anyone has an idea what is happening here? Just a simple line of code
creating a dummy entry that my model could evaluate() would unstuck me, I think.
machine-learning python keras tensorflow
machine-learning python keras tensorflow
asked Mar 30 at 19:19
JoëlJoël
1936
1936
$begingroup$
Trymodel.evaluate(np.random.random((100, 3)))
$endgroup$
– Vaalizaadeh
Mar 30 at 19:41
add a comment |
$begingroup$
Trymodel.evaluate(np.random.random((100, 3)))
$endgroup$
– Vaalizaadeh
Mar 30 at 19:41
$begingroup$
Try
model.evaluate(np.random.random((100, 3)))
$endgroup$
– Vaalizaadeh
Mar 30 at 19:41
$begingroup$
Try
model.evaluate(np.random.random((100, 3)))
$endgroup$
– Vaalizaadeh
Mar 30 at 19:41
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
model.evaluate
requires both input and output, for example
evaluation = model.evaluate(np.random.random((1, 100)), np.random.random((1, 1)))
I think a step-by-step example would be more beneficial. Here is a working example:
from keras.models import Sequential
from keras.layers import Dense
import numpy as np
N = 1000
dimension = 100
# create some random input features (x) and output (y)
np.random.seed(0)
x = np.random.random((N, dimension))
y = np.random.random((N,))
# split the data into train and test sets
split = int(0.8 * N)
x_train = x[:split]
y_train = y[:split]
x_test = x[split:]
y_test = y[split:]
# build the model architecture
model = Sequential()
model.add(Dense(32, activation='relu', input_dim=dimension))
model.add(Dense(1, activation='sigmoid'))
model.compile(optimizer='rmsprop',
loss='binary_crossentropy',
metrics=['accuracy'])
# train the model
model.fit(x_train, y_train, epochs=100)
# evaluate the model on train and test sets
train_loss = model.evaluate(x_train, y_train)[0]
test_loss = model.evaluate(x_test, y_test)[0]
print('train loss:', train_loss, ', test loss:', test_loss)
# predict (y) for a random input (x)
y_predict = model.predict(np.random.random((1, dimension)))
print('prediction:', y_predict)
which outputs binary_crossentropy
loss:
train loss: 0.5500347983837127 , test loss: 0.7403841614723206
prediction: [[0.38731796]]
If you skip the training, i.e. commenting out
# train the model
model.fit(x_train, y_train, epochs=100)
the output will be
train loss: 0.7098221921920777 , test loss: 0.7191445398330688
prediction: [[0.32682237]]
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
);
);
, "mathjax-editing");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "557"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f48273%2fproblem-of-entry-format-for-a-simple-model-in-keras%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
model.evaluate
requires both input and output, for example
evaluation = model.evaluate(np.random.random((1, 100)), np.random.random((1, 1)))
I think a step-by-step example would be more beneficial. Here is a working example:
from keras.models import Sequential
from keras.layers import Dense
import numpy as np
N = 1000
dimension = 100
# create some random input features (x) and output (y)
np.random.seed(0)
x = np.random.random((N, dimension))
y = np.random.random((N,))
# split the data into train and test sets
split = int(0.8 * N)
x_train = x[:split]
y_train = y[:split]
x_test = x[split:]
y_test = y[split:]
# build the model architecture
model = Sequential()
model.add(Dense(32, activation='relu', input_dim=dimension))
model.add(Dense(1, activation='sigmoid'))
model.compile(optimizer='rmsprop',
loss='binary_crossentropy',
metrics=['accuracy'])
# train the model
model.fit(x_train, y_train, epochs=100)
# evaluate the model on train and test sets
train_loss = model.evaluate(x_train, y_train)[0]
test_loss = model.evaluate(x_test, y_test)[0]
print('train loss:', train_loss, ', test loss:', test_loss)
# predict (y) for a random input (x)
y_predict = model.predict(np.random.random((1, dimension)))
print('prediction:', y_predict)
which outputs binary_crossentropy
loss:
train loss: 0.5500347983837127 , test loss: 0.7403841614723206
prediction: [[0.38731796]]
If you skip the training, i.e. commenting out
# train the model
model.fit(x_train, y_train, epochs=100)
the output will be
train loss: 0.7098221921920777 , test loss: 0.7191445398330688
prediction: [[0.32682237]]
$endgroup$
add a comment |
$begingroup$
model.evaluate
requires both input and output, for example
evaluation = model.evaluate(np.random.random((1, 100)), np.random.random((1, 1)))
I think a step-by-step example would be more beneficial. Here is a working example:
from keras.models import Sequential
from keras.layers import Dense
import numpy as np
N = 1000
dimension = 100
# create some random input features (x) and output (y)
np.random.seed(0)
x = np.random.random((N, dimension))
y = np.random.random((N,))
# split the data into train and test sets
split = int(0.8 * N)
x_train = x[:split]
y_train = y[:split]
x_test = x[split:]
y_test = y[split:]
# build the model architecture
model = Sequential()
model.add(Dense(32, activation='relu', input_dim=dimension))
model.add(Dense(1, activation='sigmoid'))
model.compile(optimizer='rmsprop',
loss='binary_crossentropy',
metrics=['accuracy'])
# train the model
model.fit(x_train, y_train, epochs=100)
# evaluate the model on train and test sets
train_loss = model.evaluate(x_train, y_train)[0]
test_loss = model.evaluate(x_test, y_test)[0]
print('train loss:', train_loss, ', test loss:', test_loss)
# predict (y) for a random input (x)
y_predict = model.predict(np.random.random((1, dimension)))
print('prediction:', y_predict)
which outputs binary_crossentropy
loss:
train loss: 0.5500347983837127 , test loss: 0.7403841614723206
prediction: [[0.38731796]]
If you skip the training, i.e. commenting out
# train the model
model.fit(x_train, y_train, epochs=100)
the output will be
train loss: 0.7098221921920777 , test loss: 0.7191445398330688
prediction: [[0.32682237]]
$endgroup$
add a comment |
$begingroup$
model.evaluate
requires both input and output, for example
evaluation = model.evaluate(np.random.random((1, 100)), np.random.random((1, 1)))
I think a step-by-step example would be more beneficial. Here is a working example:
from keras.models import Sequential
from keras.layers import Dense
import numpy as np
N = 1000
dimension = 100
# create some random input features (x) and output (y)
np.random.seed(0)
x = np.random.random((N, dimension))
y = np.random.random((N,))
# split the data into train and test sets
split = int(0.8 * N)
x_train = x[:split]
y_train = y[:split]
x_test = x[split:]
y_test = y[split:]
# build the model architecture
model = Sequential()
model.add(Dense(32, activation='relu', input_dim=dimension))
model.add(Dense(1, activation='sigmoid'))
model.compile(optimizer='rmsprop',
loss='binary_crossentropy',
metrics=['accuracy'])
# train the model
model.fit(x_train, y_train, epochs=100)
# evaluate the model on train and test sets
train_loss = model.evaluate(x_train, y_train)[0]
test_loss = model.evaluate(x_test, y_test)[0]
print('train loss:', train_loss, ', test loss:', test_loss)
# predict (y) for a random input (x)
y_predict = model.predict(np.random.random((1, dimension)))
print('prediction:', y_predict)
which outputs binary_crossentropy
loss:
train loss: 0.5500347983837127 , test loss: 0.7403841614723206
prediction: [[0.38731796]]
If you skip the training, i.e. commenting out
# train the model
model.fit(x_train, y_train, epochs=100)
the output will be
train loss: 0.7098221921920777 , test loss: 0.7191445398330688
prediction: [[0.32682237]]
$endgroup$
model.evaluate
requires both input and output, for example
evaluation = model.evaluate(np.random.random((1, 100)), np.random.random((1, 1)))
I think a step-by-step example would be more beneficial. Here is a working example:
from keras.models import Sequential
from keras.layers import Dense
import numpy as np
N = 1000
dimension = 100
# create some random input features (x) and output (y)
np.random.seed(0)
x = np.random.random((N, dimension))
y = np.random.random((N,))
# split the data into train and test sets
split = int(0.8 * N)
x_train = x[:split]
y_train = y[:split]
x_test = x[split:]
y_test = y[split:]
# build the model architecture
model = Sequential()
model.add(Dense(32, activation='relu', input_dim=dimension))
model.add(Dense(1, activation='sigmoid'))
model.compile(optimizer='rmsprop',
loss='binary_crossentropy',
metrics=['accuracy'])
# train the model
model.fit(x_train, y_train, epochs=100)
# evaluate the model on train and test sets
train_loss = model.evaluate(x_train, y_train)[0]
test_loss = model.evaluate(x_test, y_test)[0]
print('train loss:', train_loss, ', test loss:', test_loss)
# predict (y) for a random input (x)
y_predict = model.predict(np.random.random((1, dimension)))
print('prediction:', y_predict)
which outputs binary_crossentropy
loss:
train loss: 0.5500347983837127 , test loss: 0.7403841614723206
prediction: [[0.38731796]]
If you skip the training, i.e. commenting out
# train the model
model.fit(x_train, y_train, epochs=100)
the output will be
train loss: 0.7098221921920777 , test loss: 0.7191445398330688
prediction: [[0.32682237]]
edited Apr 1 at 10:19
answered Mar 30 at 19:42
EsmailianEsmailian
2,805318
2,805318
add a comment |
add a comment |
Thanks for contributing an answer to Data Science Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f48273%2fproblem-of-entry-format-for-a-simple-model-in-keras%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
Try
model.evaluate(np.random.random((100, 3)))
$endgroup$
– Vaalizaadeh
Mar 30 at 19:41