Edited, memorised or added to reading queue

on 09-May-2024 (Thu)

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

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




TfC_02_classification-PART_2
#tensorflow #tensorflow-certificate

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 classification models.


Confusion matrix

Can be hard to use whith large numbers of classes.

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)

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()

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




#tensorflow #tensorflow-certificate
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="int32") #to avoid bool which generate problem with model fitting in TensorFlow
insurance_one_hot
statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

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 7626517253388

Tags
#tensorflow #tensorflow-certificate
Question
Preprocessing data

ct = [...]((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)
Answer
make_column_transformer

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

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







Flashcard 7626518826252

Tags
#tensorflow #tensorflow-certificate
Question
Preprocessing data

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

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







Flashcard 7626519874828

Tags
#tensorflow #tensorflow-certificate
Question
Preprocessing data

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

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







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
Typical workflow: build a model -> fit it -> evaulate -> tweak -> fit > evaluate -> ....
statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

TfC 01 regression
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 <span>Typical workflow: build a model -> fit it -> evaulate -> tweak -> fit > evaluate -> .... 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




[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




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

What can visualize?

  • the data
  • model itself
  • the training of a model
  • predictions
statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

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




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

## The 3 sets (or actually 2 sets: training and test set) - USING ONLY TensorFlow

tf.random.set_seed(999)

X_train, X_test = tf.split(tf.random.shuffle(X, seed=42), num_or_size_splits=[40, 10])

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

TfC 01 regression
> evaulate -> tweak -> fit > evaluate -> .... Building model: experiment Evaluation model: visualize What can visualize? the data model itself the training of a model predictions <span>## 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_predictions(train_data = X_train, train_labels = y_train, test_data = X_test, test_labels = y_test, predictions = y_pred): """ Plots training data, testing_data """ plt.figure(




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

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.

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

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 7626533244172

Tags
#has-images #recurrent-neural-networks #rnn
[unknown IMAGE 7101515435276]
Question
A schematic high-level representation of the proposed model architecture is shown in Fig. 2. The structure of the model begins with its input layers for (i) the input variable (i.e., [...]) and (ii) optional covariates (time-invariant or time-varying inputs). These variable inputs enter the model through dedicated input layers at the top of the model’s architecture and are combined by simply concatenating them into a single long vector. This input signal then propagates through a series of intermediate layers including a specialized LSTM, or Long Short-Term Memory RNN neural network component.
Answer
transaction counts

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
pan> A schematic high-level representation of the proposed model architecture is shown in Fig. 2. The structure of the model begins with its input layers for (i) the input variable (i.e., transaction counts) and (ii) optional covariates (time-invariant or time-varying inputs). These variable inputs enter the model through dedicated input layers at the top of the model’s architecture and ar

Original toplevel document (pdf)

cannot see any pdfs







Flashcard 7626535079180

Tags
#deep-learning #has-images #keras #lstm #python #sequence
[unknown IMAGE 7104082873612]
Question
LSTMs work by learning a function ( f( ) that [...] input sequence values ( X ) onto output sequence values (y)
Answer
maps

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
LSTMs work by learning a function ( f(...) ) that maps input sequence values ( X ) onto output sequence values (y)

Original toplevel document (pdf)

cannot see any pdfs







#deep-learning #keras #lstm #python #sequence
Some examples of sequence prediction problems include: Weather Forecasting . Given a sequence of observations about the weather over time, predict the expected weather tomorrow.
statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on


Parent (intermediate) annotation

Open it
Some examples of sequence prediction problems include: Weather Forecasting . Given a sequence of observations about the weather over time, predict the expected weather tomorrow. Stock Market Prediction . Given a sequence of movements of a security over time, predict the next movement of the security. Product Recommendation . Given a sequence of past purchases f

Original toplevel document (pdf)

cannot see any pdfs




Flashcard 7626538224908

Tags
#deep-learning #keras #lstm #python #sequence
Question
Sequence generation involves generating a new output sequence that has the same [...] as other sequences in the corpus. For example: Input Sequence: [1, 3, 5], [7, 9, 11] Output Sequence: [3, 5 ,7]
Answer
general characteristics

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
Sequence generation involves generating a new output sequence that has the same general characteristics as other sequences in the corpus. For example: Input Sequence: [1, 3, 5], [7, 9, 11] Output Sequence: [3, 5 ,7]

Original toplevel document (pdf)

cannot see any pdfs







#RNN #ariadne #behaviour #consumer #deep-learning #priority #recurrent-neural-networks #retail #simulation #synthetic-data
To achieve better explainability, in many e-commerce applications consumer behavior can be viewed on the level of sessions. A session is a well-defined visit of a consumer to a web- shop: a subsequence of events within the consumer’s history that lay no further apart than a predefined time difference.
statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on


Parent (intermediate) annotation

Open it
Recognizing relevant patterns in long input streams (> 100 actions) can turn out to be difficult for the human mind. To achieve better explainability, in many e-commerce applications consumer behavior can be viewed on the level of sessions. A session is a well-defined visit of a consumer to a web- shop: a subsequence of events within the consumer’s history that lay no further apart than a predefined time difference. Here, we split sequences of events into different sessions if there is a time gap of more than 30 minutes in-between subsequent events.

Original toplevel document (pdf)

cannot see any pdfs




Flashcard 7626541632780

Tags
#pytest #python #unittest
Question

Beware of float return values!
0.1 + 0.1 + 0.1 == 0.3 Sometimes false

assert 0.1 + 0.1 + 0.1 == 0.3, "Usual way to compare does not always work with floats!"

Instead use:

[...] 0.1 + 0.1 + 0.1 == pytest.approx(0.3)

Answer
assert

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

Open it
Beware of float return values! 0.1 + 0.1 + 0.1 == 0.3 Sometimes false assert 0.1 + 0.1 + 0.1 == 0.3, "Usual way to compare does not always work with floats!" Instead use: assert 0.1 + 0.1 + 0.1 == pytest.approx(0.3)







Flashcard 7626542943500

Tags
#has-images #recurrent-neural-networks #rnn
[unknown IMAGE 7101511240972]
Question
Note that the model is completely [...] about further extensions: all individual-level, cohort-level, time-varying, or time-invariant covariates are simply encoded as categorical input variables, and are handled equally by the model
Answer
agnostic

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
Note that the model is completely agnostic about further extensions: all individual-level, cohort-level, time-varying, or time-invariant covariates are simply encoded as categorical input variables, and are handled equally by th

Original toplevel document (pdf)

cannot see any pdfs







#recurrent-neural-networks #rnn
We highlight our model’s flexibility and performance on two groups of valuable customers: those who keep making more and more transactions with the firm (denoted as ”opportunity” customers) and those who are at risk of defection. We demonstrate that the model also excels at automatically capturing seasonal trends in customer activity, such as the shopping period leading up to the December holidays.
statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on


Parent (intermediate) annotation

Open it
lso accurately predicts periods of elevated transaction activity and captures other forms of purchase dynamics that can be leveraged in simulations of future sequences of customer transactions. <span>We highlight our model’s flexibility and performance on two groups of valuable customers: those who keep making more and more transactions with the firm (denoted as ”opportunity” customers) and those who are at risk of defection. We demonstrate that the model also excels at automatically capturing seasonal trends in customer activity, such as the shopping period leading up to the December holidays. In Appendix Section F we provide a further characterization of scenarios where our model performs particularly well and where it does not do so relative to the used benchmark methods. </sp

Original toplevel document (pdf)

cannot see any pdfs




Flashcard 7626546089228

Tags
#deep-learning #keras #lstm #python #sequence
Question
Epoch : One pass through [...] in the training dataset and updating the network weights. LSTMs may be trained for tens, hundreds, or thousands of epochs.
Answer
all samples

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
Epoch : One pass through all samples in the training dataset and updating the network weights. LSTMs may be trained for tens, hundreds, or thousands of epochs.

Original toplevel document (pdf)

cannot see any pdfs







Flashcard 7626547662092

Tags
#ML-engineering #ML_in_Action #learning #machine #software-engineering
Question
Testing approaches is a Goldilocks activity; if you don’t test enough options, you’re probably not finding the best solution, while testing too many things wastes precious time. Find the [...]
Answer
middle ground.

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
Testing approaches is a Goldilocks activity; if you don’t test enough options, you’re probably not finding the best solution, while testing too many things wastes precious time. Find the middle ground. <span>

Original toplevel document (pdf)

cannot see any pdfs