Edited, memorised or added to reading queue

on 15-May-2024 (Wed)

Do you want BuboFlash to help you learning these things? Click here to log in or create user.

Flashcard 7626440445196

Tags
#tensorflow #tensorflow-certificate
Question
#### Def some functions to calculate losses (mae, mse)

def evaluate_mae(y_true, y_pred):
  return tf.keras.[...].mean_absolute_error(y_true = y_true,
                                      y_pred = tf.squeeze(y_pred))

Answer
losses

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

Open it
#### Def some functions to calculate losses (mae, mse) def evaluate_mae(y_true, y_pred): return tf.keras.losses.mean_absolute_error(y_true = y_true, y_pred = tf.squeeze(y_pred))







TfC_02_classification-PART_1
#tensorflow #tensorflow-certificate

Types of classification problems

Three types of classification problems:

  • binary classification
  • multiclass
  • multilabel

Multilabel classification - a sample can be assigned to more than one label from more than 2 label options
Multiclass classification - a sample can be assigned to one label but from more than 2 label options

Multiclass image classificaton: pizza, steak, sushi

Input_shape = [None, 224, 224, 3] - single image

Input shape = [32, 224, 224, 3] - common batch size of images

32 is a common batch size

...
statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on




Flashcard 7626520923404

Tags
#tensorflow #tensorflow-certificate
Question

Preprocessing data

ct = make_column_transformer((OneHotEncoder(dtype="int32"), ['Sex']), remainder="passthrough") #other columns unchangaed
ct.[...](X_train) 
X_train_transformed = ct.transform(X_train)
X_test_transformed = ct.transform(X_test)
Answer
fit

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

Parent (intermediate) annotation

Open it
Preprocessing data ct = make_column_transformer((OneHotEncoder(dtype="int32"), ['Sex']), remainder="passthrough") #other columns unchangaed ct.fit(X_train) X_train_transformed = ct.transform(X_train) X_test_transformed = ct.transform(X_test)

Original toplevel document

TfC_01_ADDITIONAL_01_Abalone.ipynb
Preprocessing data ct = make_column_transformer((OneHotEncoder(dtype="int32"), ['Sex']), remainder="passthrough") #other columns unchangaed ct.fit(X_train) X_train_transformed = ct.transform(X_train) X_test_transformed = ct.transform(X_test) Predictions valuation_predicts = model.predict(X_valuation_transformed) (array([[ 9.441547], [10.451973], [10.48082 ], ..., [10.401164], [13.13452 ], [ 8.081818]], dtype=float32), (6041







[unknown IMAGE 7626420784396] #has-images #tensorflow #tensorflow-certificate

How we can improve model (in the particular stage of the process)?

# 1. Creating model: add more layers, increase numbers of hidden neurons, change activation functions

# 2. Compiling: change optimizer or its parameters (eg. learning rate)

# 3. Fitting: more epochs, more data

### How?

# from smaller model to larger model

statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

TfC 01 regression
#### How we can improve model # 1. Creating model: add more layers, increase numbers of hidden neurons, change activation functions # 2. Compiling: change optimizer or its parameters (eg. learning rate) # 3. Fitting: more epochs, more data ### How? # from smaller model to larger model Evaluating models Typical workflow: build a model -> fit it -> evaulate -> tweak -> fit > evaluate -> .... Building model: experiment Evaluation model: visualize What




[unknown IMAGE 7626420784396] #has-images #tensorflow #tensorflow-certificate

Deep Learning mantras: ;)

Building model: experiment
Evaluation model: visualize

statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

TfC 01 regression
more epochs, more data ### How? # from smaller model to larger model Evaluating models Typical workflow: build a model -> fit it -> evaulate -> tweak -> fit > evaluate -> .... <span>Building model: experiment Evaluation model: visualize What can visualize? the data model itself the training of a model predictions ## The 3 sets (or actually 2 sets: training and test set) tf.random.set_seed(999) X_train, X_test = tf.spli




#tensorflow #tensorflow-certificate
Multiclass classification - a sample can be assigned to one label but from more than 2 label options
statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

TfC_02_classification-PART_1
ms Three types of classification problems: binary classification multiclass multilabel Multilabel classification - a sample can be assigned to more than one label from more than 2 label options <span>Multiclass classification - a sample can be assigned to one label but from more than 2 label options Multiclass image classificaton: pizza, steak, sushi Input_shape = [None, 224, 224, 3] - single image Input shape = [32, 224, 224, 3] - common batch size of images 32 is a common batch s




#tensorflow #tensorflow-certificate
Multilabel classification - a sample can be assigned to more than one label from more than 2 label options
statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

TfC_02_classification-PART_1
Types of classification problems Three types of classification problems: binary classification multiclass multilabel Multilabel classification - a sample can be assigned to more than one label from more than 2 label options Multiclass classification - a sample can be assigned to one label but from more than 2 label options Multiclass image classificaton: pizza, steak, sushi Input_shape = [None, 224, 224, 3




#tensorflow #tensorflow-certificate

important:

This time there is a problem with loss function.

  • In case of categorical_crossentropy the labels have to be one-hot encoded

  • In case of labels as integeres use SparseCategoricalCrossentropy

statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

TfC_02_classification-PART_2
y-axis -> true label x-axis -> predicted label # Create confusion metrics from sklearn.metrics import confusion_matrix y_preds = model_8.predict(X_test) confusion_matrix(y_test, y_preds) <span>important: This time there is a problem with loss function. In case of categorical_crossentropy the labels have to be one-hot encoded In case of labels as integeres use SparseCategoricalCrossentropy # Get the patterns of a layer in our network weights, biases = model_35.layers[1].get_weights() <span>




#tensorflow #tensorflow-certificate
Recall

Higher recall leads to less false negatives.

statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

TfC_02_classification-PART_2
ccuracy tf.keras.metrics.Accuracy() sklearn.metrics.accuracy_score() Not the best for imbalanced classes Precision For imbalanced class problems. Higher precision leads to less false positives. <span>Recall Higher recall leads to less false negatives. Tradeoff between recall and precision. F1-score Combination of precision and recall, ususally a good overall metric for classification models. keyboard_arrow_down Confusion matrix Can b




#tensorflow #tensorflow-certificate
Precision

For imbalanced class problems. Higher precision leads to less false positives.

statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

TfC_02_classification-PART_2
Classification evaluation methods Accuracy tf.keras.metrics.Accuracy() sklearn.metrics.accuracy_score() Not the best for imbalanced classes Precision For imbalanced class problems. Higher precision leads to less false positives. Recall Higher recall leads to less false negatives. Tradeoff between recall and precision. F1-score Combination of precision and recall, ususally a good overall metric for classificatio




[unknown IMAGE 7626420784396] #has-images #tensorflow #tensorflow-certificate

How we can improve model (in the particular stage of the process)?

# 1. Creating model: add more layers, increase numbers of hidden neurons, change activation functions

statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on


Parent (intermediate) annotation

Open it
How we can improve model (in the particular stage of the process)? # 1. Creating model: add more layers, increase numbers of hidden neurons, change activation functions # 2. Compiling: change optimizer or its parameters (eg. learning rate) # 3. Fitting: more epochs, more data ### How? # from smaller model to larger model

Original toplevel document

TfC 01 regression
#### How we can improve model # 1. Creating model: add more layers, increase numbers of hidden neurons, change activation functions # 2. Compiling: change optimizer or its parameters (eg. learning rate) # 3. Fitting: more epochs, more data ### How? # from smaller model to larger model Evaluating models Typical workflow: build a model -> fit it -> evaulate -> tweak -> fit > evaluate -> .... Building model: experiment Evaluation model: visualize What




[unknown IMAGE 7626420784396] #has-images #tensorflow #tensorflow-certificate

How we can improve model (in the particular stage of the process)?

# 2. Compiling: change optimizer or its parameters (eg. learning rate)

statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on


Parent (intermediate) annotation

Open it
How we can improve model (in the particular stage of the process)? # 1. Creating model: add more layers, increase numbers of hidden neurons, change activation functions # 2. Compiling: change optimizer or its parameters (eg. learning rate) # 3. Fitting: more epochs, more data ### How? # from smaller model to larger model

Original toplevel document

TfC 01 regression
#### How we can improve model # 1. Creating model: add more layers, increase numbers of hidden neurons, change activation functions # 2. Compiling: change optimizer or its parameters (eg. learning rate) # 3. Fitting: more epochs, more data ### How? # from smaller model to larger model Evaluating models Typical workflow: build a model -> fit it -> evaulate -> tweak -> fit > evaluate -> .... Building model: experiment Evaluation model: visualize What




[unknown IMAGE 7626420784396] #has-images #tensorflow #tensorflow-certificate

How we can improve model (in the particular stage of the process)?

# 3. Fitting: more epochs, more data

statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on


Parent (intermediate) annotation

Open it
How we can improve model (in the particular stage of the process)? # 1. Creating model: add more layers, increase numbers of hidden neurons, change activation functions # 2. Compiling: change optimizer or its parameters (eg. learning rate) # 3. Fitting: more epochs, more data ### How? # from smaller model to larger model

Original toplevel document

TfC 01 regression
#### How we can improve model # 1. Creating model: add more layers, increase numbers of hidden neurons, change activation functions # 2. Compiling: change optimizer or its parameters (eg. learning rate) # 3. Fitting: more epochs, more data ### How? # from smaller model to larger model Evaluating models Typical workflow: build a model -> fit it -> evaulate -> tweak -> fit > evaluate -> .... Building model: experiment Evaluation model: visualize What




#tensorflow #tensorflow-certificate
  1. Converting non-numerical columns

For example: Use pandas get_dummies() function

statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on


Parent (intermediate) annotation

Open it
Getting dataset ready for tensorflow Converting non-numerical columns For example: Use pandas get_dummies() function insurance_one_hot = pd.get_dummies(insurance,dtype="int32") #to avoid bool which generate problem with model fitting in TensorFlow insurance_one_hot

Original toplevel document

TfC_01_FINAL_EXAMPLE.ipynb
Getting dataset ready for tensorflow Converting non-numerical columns For example: Use pandas get_dummies() function 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




Flashcard 7627269082380

Tags
#tensorflow #tensorflow-certificate
Question
Getting dataset ready for tensorflow
  1. Converting non-numerical columns

For example: Use pandas get_dummies() function

insurance_one_hot = pd.get_dummies(insurance,dtype=[...]) #to avoid bool which generate problem with model fitting in TensorFlow
insurance_one_hot
Answer
"int32"

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

Parent (intermediate) annotation

Open it
Getting dataset ready for tensorflow Converting non-numerical columns For example: Use pandas get_dummies() function insurance_one_hot = pd.get_dummies(insurance,dtype="int32") #to avoid bool which generate problem with model fitting in TensorFlow insurance_one_hot

Original toplevel document

TfC_01_FINAL_EXAMPLE.ipynb
Getting dataset ready for tensorflow Converting non-numerical columns For example: Use pandas get_dummies() function 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







[unknown IMAGE 7626420784396] #has-images #tensorflow #tensorflow-certificate
MAE
  • tf.keras.losses.MAE()
  • tf.metrics.mean_absolute_error()
  • great starter metrics for any regression problem
statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on


Parent (intermediate) annotation

Open it
For regression problems: MAE tf.keras.losses.MAE() tf.metrics.mean_absolute_error() great starter metrics for any regression problem MSE tf.keras.losses.MSE() tf.metrics.mean_square_error() when larger errors are more significant that smaller errors Huber tf.keras.losses.Huber() combintion of MSE and MAE less sensiti

Original toplevel document

TfC 01 regression
st_labels, c="green", label="Testing data") plt.scatter(test_data, predictions, c="red", label="Predictions") plt.legend(); Common regression evaluation metrics keyboard_arrow_down Introduction <span>For regression problems: MAE tf.keras.losses.MAE() tf.metrics.mean_absolute_error() great starter metrics for any regression problem MSE tf.keras.losses.MSE() tf.metrics.mean_square_error() 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 t




Flashcard 7627273800972

Tags
#has-images #tensorflow #tensorflow-certificate
[unknown IMAGE 7626420784396]
Question

Load model

loaded_model_SM = tf.keras.models.[...]('/content/best_model_3_SavedModel')
loaded_model_SM.summary()

Answer
load_model

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

Parent (intermediate) annotation

Open it
Load model loaded_model_SM = tf.keras.models.load_model('/content/best_model_3_SavedModel') loaded_model_SM.summary()

Original toplevel document

TfC 01 regression
# 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") <span>Load model loaded_model_SM = tf.keras.models.load_model('/content/best_model_3_SavedModel') loaded_model_SM.summary() <span>







Flashcard 7627275635980

Tags
#has-images #tensorflow #tensorflow-certificate
[unknown IMAGE 7626420784396]
Question

Load model

loaded_model_SM = tf.keras.[...].load_model('/content/best_model_3_SavedModel')
loaded_model_SM.summary()

Answer
models

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

Parent (intermediate) annotation

Open it
Load model loaded_model_SM = tf.keras.models.load_model('/content/best_model_3_SavedModel') loaded_model_SM.summary()

Original toplevel document

TfC 01 regression
# 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") <span>Load model loaded_model_SM = tf.keras.models.load_model('/content/best_model_3_SavedModel') loaded_model_SM.summary() <span>







Flashcard 7627276946700

Tags
#has-images #tensorflow #tensorflow-certificate
[unknown IMAGE 7626420784396]
Question

Saving and loading models

Two formats:

  • SavedModel format (including [...] step)
  • HDF5 format
Answer
optimizer's

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

Parent (intermediate) annotation

Open it
Saving and loading models Two formats: SavedModel format (including optimizer's step) HDF5 format

Original toplevel document

TfC 01 regression
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 <span>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") Load model loaded_model_SM = tf.keras.models.load_model('/content/best_model_3_SavedModel') loaded_model_SM.summary() <span>







Flashcard 7627278781708

Tags
#has-images #tensorflow #tensorflow-certificate
[unknown IMAGE 7626420784396]
Question

What can visualize?

  • the data
  • model itself
  • the training of a model
  • [...]
Answer
predictions

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

Parent (intermediate) annotation

Open it
What can visualize? the data model itself the training of a model predictions

Original toplevel document

TfC 01 regression
larger model Evaluating models Typical workflow: build a model -> fit it -> evaulate -> tweak -> fit > evaluate -> .... Building model: experiment Evaluation model: visualize <span>What can visualize? the data model itself the training of a model predictions ## The 3 sets (or actually 2 sets: training and test set) tf.random.set_seed(999) X_train, X_test = tf.split(tf.random.shuffle(X, seed=42), num_or_size_splits=[40, 10]) def plot_predict







#tensorflow #tensorflow-certificate

# Create X and y values (features and labels)

y = insurance_one_hot['charges']

X = insurance_one_hot.drop('charges', axis=1)

statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

TfC_01_FINAL_EXAMPLE.ipynb
r example: Use pandas get_dummies() function insurance_one_hot = pd.get_dummies(insurance,dtype="int32") #to avoid bool which generate problem with model fitting in TensorFlow insurance_one_hot <span># 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_