Nurdin
Nurdin

Reputation: 23883

Keras - How to predict based on one instance?

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

Upvotes: 1

Views: 876

Answers (1)

shanecandoit
shanecandoit

Reputation: 621

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)

Upvotes: 3

Related Questions