325
325

Reputation: 606

Using a Neural Network to Predict Output From a New Observation

I have constructed a neural network using Python's Keras package. My network's goal is to predict the price of house. Here is what my training dataset looked like.

    Price   Beds    SqFt    Built   Garage  FullBaths   HalfBaths   LotSqFt
    485000  3       2336    2004    2       2.0          1.0        2178.0
    430000  4       2106    2005    2       2.0          1.0        2178.0
    445000  3       1410    1999    1       2.0          0.0        3049.0

...

Suppose I have some new houses I want to analyze. For example, I want to predict the price of a house with

How can I input these values into my network to receive a predicted price. Also, is there a way to have the network report some kind of confidence indicator?

For reference, here is what my network currently looks like.

from keras.models import Sequential
from keras.layers import Dense

N = 16

model = Sequential([
    Dense(N, activation='relu', input_shape=(7,)),
    Dense(1, activation='relu'),
])

model.compile(optimizer='sgd',
              loss='mse',
              metrics=['mean_squared_error'])

hist = model.fit(X_train, Y_train,
          batch_size=32, epochs=100,
          validation_data=(X_val, Y_val))

model.evaluate(X_test, Y_test)[1]

Thanks in advance!!

Upvotes: 1

Views: 324

Answers (1)

Ivo De Jong
Ivo De Jong

Reputation: 199

For this you'll want to use model.predict(), as documented here.

model.predict() takes as parameter a batch of inputs x. In your case you only have 1 input, so you could write this as:

x = [[4, 2500, 2001, 0, 3, 1, 3452]] # Assumes 0 garages
print(model.predict(x)[0]) # Print the first (only) result

Upvotes: 1

Related Questions