I am trying to create an AI that will predict a person’s weight from their height. Everything seems to work without any compiler errors. Here’s my code:
import numpy as np
from random import randint
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
input_dim=1
output_dim = 1
x_train,y_train = [65,68,70,72,67,69,71,66,73,64],[150,160,175,180,155,165,170,148,185,142]
model = Sequential()
model.add(Dense(64, input_shape=(input_dim,), activation='relu'))
model.add(Dense(32, activation='relu'))
model.add(Dense(output_dim, activation='linear'))
model.compile(optimizer='adam', loss='mean_squared_error', metrics=['accuracy'])
model.fit(np.array(x_train), np.array(y_train), epochs=10, batch_size=32)
while True:
height = float(input("Enter height:"))
new_height = np.array([[height]])
print("Weight:",model.predict(new_height))
In my training data, x_train represents heights in inches, while y_train represents weight in pounds.
However, whenever I enter a height to predict the weight, I get strange numbers that don’t correlate to my data:
Enter height:70
Weight: [[-2.168133]]
I would have expected something around 175 instead.
Why is this happening? Is this because my data set is too small?
user24657620 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.