when larger errors are more significant that smaller errors
Huber
tf.keras.losses.Huber()
combintion of MSE and MAE less sensitive to outliers than MSE
Take away: You should minimize the time between your experiments (that's way you should start with smaller models). The more experiments you do, the more things you figure out that don't work.
Tracking your experiments
One really good habit is to track the results of your experiments. There are tools to help us!
Resource: Try:
Tensorboard - a component of Tensorflow library to help track modelling experiments
Weights & Biases
Saving and loading models
Two formats:
SavedModel format (including optimizer's step)
HDF5 format
What about TensorFlow Serving format?
# Save the entire model using SavedModel
model_3.save("best_model_3_SavedModel")
# SavedModel is in principle protobuff)pb file
# Save model in HDF5 format:
model_3.save("best_model_3_HDF5.h5")
insurance_one_hot = pd.get_dummies(insurance,dtype="int32") #to avoid bool which generate problem with model fitting in TensorFlow
insurance_one_hot
# Create X and y values (features and labels)
y = insurance_one_hot['charges']
X = insurance_one_hot.drop('charges', axis=1)
#y = y.values # This is not necessary
#X = X.values
#X, y, X.shape, y.shape
# Create training and test datasets
#my way:
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state=42)
Preprocessing data (normalization and standardization)
Preprocessing steps:
Turn all data into numbers
Make sure your tensors are in the right shape
Scale features (normalize or standardize) Neural networks tend to prefer normalization.
Normalization - adjusting values measured on different scales to a notionally common scale
Normalization
# Start from scratch
import pandas as pd
import matplotlib.pyplot as plt
import tensorflow as tf
## Borrow a few classes from sci-kit learn
from sklearn.compose import make_column_transformer
from sklearn.preprocessing import MinMaxScaler, OneHotEncoder
from sklearn.model_selection import train_test_split
#Create column transformer
ct = make_column_transformer((MinMaxScaler(), ['age', 'bmi', 'children']), # turn all values in these columns between 0 and 1
(OneHotEncoder(handle_unknown='ignore', dtype="int32"), ['sex', 'smoker', 'region']))
# Create X and y
X = insurance.drop('charges', axis=1)
y = insurance['charges']
# Split datasets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Fit the column transformer on training data and apply to both datasets (train and test)
ct.fit(X_train)
# Transform data
X_train_normalize = ct.transform(X_train)
X_test_normalize = ct.transform(X_test)
Step 1 is to gather the data. You'll notice that there's a bit of a change here in that the training data needed to be reshaped. That's because the first convolution expects a single tensor containing everything, so instead of 60,000 28x28x1 items in a list, we have a single [...dimensions?] list that is 60,000x28x28x1,
Answer
4D
status
not learned
measured difficulty
37% [default]
last interval [days]
repetition number in this series
0
memorised on
scheduled repetition
scheduled repetition interval
last repetition or drill
Parent (intermediate) annotation
Open it that the training data needed to be reshaped. That's because the first convolution expects a single tensor containing everything, so instead of 60,000 28x28x1 items in a list, we have a single <span>4D list that is 60,000x28x28x1, <span>
Original toplevel document
Convolution Neural Network - introduction Step 1 is to gather the data. You'll notice that there's a bit of a change here in that the training data needed to be reshaped. That's because the first convolution expects a single tensor containing everything, so instead of 60,000 28x28x1 items in a list, we have a single 4D list that is 60,000x28x28x1, and the same for the test images. If you don't do this, you'll get an error when training as the Convolutions do not recognize the shape. import tensorflow as tf mnist = tf.keras.datase