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










2












$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.










share|improve this question









$endgroup$











  • $begingroup$
    Try model.evaluate(np.random.random((100, 3)))
    $endgroup$
    – Vaalizaadeh
    Mar 30 at 19:41
















2












$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.










share|improve this question









$endgroup$











  • $begingroup$
    Try model.evaluate(np.random.random((100, 3)))
    $endgroup$
    – Vaalizaadeh
    Mar 30 at 19:41














2












2








2





$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.










share|improve this question









$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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 30 at 19:19









JoëlJoël

1936




1936











  • $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
















$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











1 Answer
1






active

oldest

votes


















2












$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]]





share|improve this answer











$endgroup$













    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
    );



    );













    draft saved

    draft discarded


















    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









    2












    $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]]





    share|improve this answer











    $endgroup$

















      2












      $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]]





      share|improve this answer











      $endgroup$















        2












        2








        2





        $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]]





        share|improve this answer











        $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]]






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Apr 1 at 10:19

























        answered Mar 30 at 19:42









        EsmailianEsmailian

        2,805318




        2,805318



























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Adding axes to figuresAdding axes labels to LaTeX figuresLaTeX equivalent of ConTeXt buffersRotate a node but not its content: the case of the ellipse decorationHow to define the default vertical distance between nodes?TikZ scaling graphic and adjust node position and keep font sizeNumerical conditional within tikz keys?adding axes to shapesAlign axes across subfiguresAdding figures with a certain orderLine up nested tikz enviroments or how to get rid of themAdding axes labels to LaTeX figures

            Luettelo Yhdysvaltain laivaston lentotukialuksista Lähteet | Navigointivalikko

            Gary (muusikko) Sisällysluettelo Historia | Rockin' High | Lähteet | Aiheesta muualla | NavigointivalikkoInfobox OKTuomas "Gary" Keskinen Ancaran kitaristiksiProjekti Rockin' High