I have an understanding of this error, it means that the input that I'm passing to the model is of a different dimension that what was expected. The error also states that the input that I'm passing is of the dimension (1,) while it was expecting (2,)
I have tested the input value dimension by using x.shape and it prints out (2,) still the error exists. As a counter-intuitive move I picked one of the data that was in the training data and printed the shape of the zeroth element x1[0].shape also used that as an input, the error still exists.
model.fit works well, having error with model.predict (tried passing one of the training data hardcoded, still doesn't work)
CODE:
import tensorflow as tf
import numpy as np
from tensorflow import keras
import csv
x1, ys = [], []
with open('./house.csv') as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
line = 0
for row in csv_reader:
if line > 0:
x1.append([row[1], row[3]])
ys.append(row[5])
line += 1
model = tf.keras.Sequential([keras.layers.Dense(units=1, input_shape=[2])])
model.compile(optimizer='sgd', loss='mean_squared_error')
x1 = np.asarray(x1, dtype=float)
ys = np.asarray(ys, dtype=float)
model.fit(x1, ys, epochs=500)
print(x1[0].shape)
while True:
house_size = float(input('Enter the house size: '))
house_size = house_size/3000
bhks = float(input('Enter the BHK: '))
bhks = bhks/3
x = np.array([house_size, bhks])
try:
value = model.predict(x)
except Exception as e:
print(e)
print(x)
print(x.shape)
else:
value = value[0][0] * 500
print(value)