1

I already created a model (h5 and tfjs/model.json) to predict the pricing house. The problem is I don't know how to predict based on one instance? Usually, predict based on all test data. Already tried this, but not working...

model.predict(np.array([0.347669, 0.048266, 0.515875, -0.166667, 0.000000, 0.378772]))

Error message

ValueError: Error when checking input: expected dense_1_input to have shape (6,) but got array with shape (1,)

From what I'm knowing, the instance/value should be normalized (I'm using linear regression) and convert into a numpy array. Not sure how to proceed. Got some clue here but I have no idea about it. expected dense to have shape but got array with shape

Model Summary

Model: "sequential_1"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
dense_1 (Dense)              (None, 200)               1400      
_________________________________________________________________
dense_2 (Dense)              (None, 100)               20100     
_________________________________________________________________
dense_3 (Dense)              (None, 50)                5050      
_________________________________________________________________
dense_4 (Dense)              (None, 25)                1275      
_________________________________________________________________
dense_5 (Dense)              (None, 1)                 26        
=================================================================
Total params: 27,851
Trainable params: 27,851
Non-trainable params: 0
_________________________________________________________________
None
edkeveked
  • 17,989
  • 10
  • 55
  • 93
Nurdin
  • 23,382
  • 43
  • 130
  • 308

1 Answers1

3

This has the expected shape

import numpy as np
a=np.array([[0.347669, 0.048266, 0.515875, -0.166667, 0.000000, 0.378772]])
print(a.shape) #(6,)

b=model.predict(a)
print(b)
Nurdin
  • 23,382
  • 43
  • 130
  • 308
shanecandoit
  • 581
  • 1
  • 3
  • 11
  • I got this, ValueError: Error when checking input: expected dense_1_input to have shape (6,) but got array with shape (1,) – Nurdin Jan 23 '20 at 19:04
  • Did you copy what I have? The object `a` has a shape of `(6,)`. You may have a problem with your network if `dense_1_input` is the name of a tensorflow layer. To see if that is the case enter this `print(model.summary())`. – shanecandoit Jan 23 '20 at 19:15
  • Already copied. Also, you can the model summary in updated question. – Nurdin Jan 23 '20 at 19:18
  • What does your model look like? What are you passing as the input to the first layer? Something like `input_shape=(784,)` (from mnist). – shanecandoit Jan 23 '20 at 19:26
  • what do you mean by model look like? Its regression data. input shape (1115, 6) – Nurdin Jan 23 '20 at 19:31
  • What does this give? `print(model.predict(np.array([103.7915359, 1.564744, 2583.5, 0, 0, 4958])))` – shanecandoit Jan 23 '20 at 19:36
  • same error message, ValueError: Error when checking input: expected dense_1_input to have shape (6,) but got array with shape (1,) – Nurdin Jan 23 '20 at 19:38
  • It's hard to know. Maybe `print(model.predict(np.array([[103.7915359, 1.564744, 2583.5, 0, 0, 4958]])))` or `print(model.predict([np.array([103.7915359, 1.564744, 2583.5, 0, 0, 4958])]))` – shanecandoit Jan 23 '20 at 19:43
  • I got this [[4518.988]] but the value doesn't make sense at all. The pricing house should be more expensive than 4518.988. – Nurdin Jan 23 '20 at 19:52
  • 1
    That error is solved. Might need a new question from here on. Your inputs were probably normalized. It's rare to have numbers larger than 1 as inputs. (103.7, 1.5, 2583.5, and 4958 are all larger than 1. I don't know what your inputs are called, maybe `print(train[0])` or `print(X[0])`. Good luck. – shanecandoit Jan 23 '20 at 19:57
  • 1
    Great job Mohammad Nurdin. Persistence pays off! – shanecandoit Jan 23 '20 at 20:01