Thursday 31 December 2020

keras 5 predict if housing price is above median price 2

 
predict house value from unknown dataset with the trained model. (above average = 1, below average = 0)

#house.py
#train on GPU
pysical_devices = tf.config.experimental.list_physical_devices('GPU')
#print("Num GPUs Available: ", len(pysical_devices))
tf.config.experimental.set_memory_growth(pysical_devices[0], True)

#load model
model = load_model('models/house.h5')

#create test samples that are different from data samples
test_samples = [
    [10000, 6, 5, 0, 1, 0, 2, 5, 0, 500],
    [12000, 7, 5, 1, 1, 1, 3, 7, 0, 600],
    [11000, 7, 5, 0, 1, 1, 3, 6, 0, 550],
    [11000, 6, 5, 0, 1, 1, 3, 6, 0, 550],
]
test_samples = np.array(test_samples)
scaler = MinMaxScaler(feature_range=(0, 1))
scaled_test_samples = scaler.fit_transform(test_samples)
print(scaled_test_samples)
#prediction
predictions = model.predict(x=scaled_test_samples, batch_size=32, verbose=1)

#predicted output index
rounded_predictions = np.argmax(predictions, axis=-1)
print(rounded_predictions)

-------------------------------------
#logs
#scaled input
[[0.  0.  0.  0.  0.  0.  0.  0.  0.  0. ]
 [1.  1.  0.  1.  0.  1.  1.  1.  0.  1. ]
 [0.5 1.  0.  0.  0.  1.  1.  0.5 0.  0.5]
 [0.5 0.  0.  0.  0.  1.  1.  0.5 0.  0.5]]

#output
[0 1 1 0]

reference:

No comments:

Post a Comment