Professional Documents
Culture Documents
01 Neural Network Regression With Tensorflow
01 Neural Network Regression With Tensorflow
01 Neural Network Regression With Tensorflow
(13, 210)
• Input shapes and output shapes of a regression model (features and labels)
• Steps in modelling
👩🍳 👩🔬
(we’ll be cooking up lots of code!)
How:
ff
fi
fi
Regression inputs and outputs
🛏x4
🛁x2 $940,000
🚗x2
Actual output
(represented as a tensor)
[bedroom, bathroom, garage] [939700]
Shape = [3] Shape = [1]
Hidden layer(s)
(learns patterns in data)
# units/neurons = 3
Note: “patterns” is an arbitrary term, you’ll often hear “embedding”, “weights”, “feature representation”,
“feature vectors” all referring to similar things.
(typical)
Source: Adapted from page 293 of Hands-On Machine Learning with Scikit-Learn, Keras &
TensorFlow Book by Aurélien Géron
🛏x4
🛁x2 $940,000
🚗x2
Input and output shapes
(represented as a tensor)
[bedroom, bathroom, garage] [939700]
Shape = [3] Shape = [1]
• Epochs — how many times the model will go through all of the
training examples.
4. Evaluate the model on the test data (how reliable are our model’s
predictions?)
Improving a model (from a model’s perspective)
Smaller model
n tf.keras.losses.MAE( )
∑i=1 yi − xi As a great starter metric for
Mean absolute error (MAE) MAE =
or
tf.metrics.mean_absolute_error( ) any regression problem.
n
1 2
Combination of MSE and MAE.
(y − f(x)) for | y − f(x) | ≤ δ,
Huber Lδ(y, f(x)) =
2
1 2
tf.keras.losses.Huber( ) Less sensitive to outliers than
δ | y − f(x) | − δ otherwise.
2
MSE.
fi
The machine learning explorer’s
motto
“Visualize, visualize, visualize”
Data
Training
Predictions
The machine learning practitioner’s
motto
👩🍳 👩🔬
(try lots of things an
d see what
tastes good)
Regression inputs and outputs
🛏x4
🛁x2 $940,000
🚗x2
Actual output
1. Turn all data into numbers (neural networks can’t handle strings)
2. Make sure all of your tensors are the right shape
3. Scale features (normalize or standardize, neural networks tend to prefer normalization)
Feature scaling
Source: Adapted from Je Hale’s Scale, Standardize, or Normalize with Scikit-Learn article.
ff
ff