Build a neural network that predicts the price of a house according to a simple formula, house pricing was as easy as a house costs 50k + 50k per bedroom, so that a 1 bedroom house costs 100k, a 2 bedroom house costs 150k etc.
Training data set
Bedroom amount [1, 2, 3, 4,]
House price [100, 150, 200, 250]
Code:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
iport numpy as np | |
from tensorflow import keras | |
# Create an 1*1 layer neuron | |
model = tf.keras.Sequential([keras.layers.Dense(units=1, input_shape=[1])]) | |
# Setting optimizer and loss function | |
model.compile(optimizer='sgd', loss='mean_squared_error') | |
# Training data | |
xs = np.array([1, 2, 3, 4], dtype=int) | |
ys = np.array([100, 150, 200, 250], dtype=int) | |
# Training mode for 500 iteration | |
model.fit(xs, ys, epochs=500) | |
# Predict the output | |
print(model.predict([7.0]))m |
沒有留言:
張貼留言