easypheno.model._tensorflow_model
Module Contents
Classes
Parent class based on |
- class easypheno.model._tensorflow_model.TensorflowModel(task, optuna_trial, encoding=None, n_outputs=1, n_features=None, width_onehot=None, batch_size=None, n_epochs=None, early_stopping_point=None)
Bases:
easypheno.model._base_model.BaseModel
,abc.ABC
Parent class based on
BaseModel
for all TensorFlow models to share functionalities. SeeBaseModel
for more information.Attributes
Inherited attributes
See
BaseModel
.Additional attributes
n_features (int): Number of input features to the model
width_onehot (int): Number of input channels in case of onehot encoding
batch_size (int): Batch size for batch-based training
n_epochs (int): Number of epochs for optimization
optimizer (tf.keras.optimizers.Optimizer): optimizer for model fitting
loss_fn: loss function for model fitting
early_stopping_patience (int): epochs without improvement before early stopping
early_stopping_point (int): epoch at which early stopping occured
early_stopping_callback (tf.keras.callbacks.EarlyStopping): callback for early stopping
- Parameters
task (str) – ML task (regression or classification) depending on target variable
optuna_trial (optuna.trial.Trial) – optuna.trial.Trial : trial of optuna for optimization
encoding (str) – the encoding to use (standard encoding or user-defined)
n_features (int) – Number of input features to the model
width_onehot (int) – Number of input channels in case of onehot encoding
batch_size (int) – Batch size for batch-based training
n_epochs (int) – Number of epochs for optimization
early_stopping_point (int) – Stop training at defined epoch
n_outputs (int) –
- train_val_loop(self, X_train, y_train, X_val, y_val)
Implementation of a train and validation loop for TensorFlow models. See
BaseModel
for more information- Parameters
X_train (numpy.array) –
y_train (numpy.array) –
X_val (numpy.array) –
y_val (numpy.array) –
- Return type
numpy.array
- retrain(self, X_retrain, y_retrain)
Implementation of the retraining for PyTorch models. See
BaseModel
for more information- Parameters
X_retrain (numpy.array) –
y_retrain (numpy.array) –
- predict(self, X_in)
Implementation of a prediction based on input features for PyTorch models. See
BaseModel
for more information- Parameters
X_in (numpy.array) –
- Return type
numpy.array
- get_dataloader(self, X, y=None, shuffle=True)
Get a dataloader using the specified data and batch size
- Parameters
X (numpy.array) – feature matrix to use
y (numpy.array) – optional target vector to use
shuffle (bool) – shuffle parameter for DataLoader
- Returns
batched dataset
- Return type
tensorflow.data.Dataset
- static common_hyperparams()
Add hyperparameters that are common for PyTorch models. Do not need to be included in optimization for every child model. Also See
BaseModel
for more information
- save_model(self, path, filename)
Method to persist the whole model object on a hard drive (can be loaded with
load_model
)- Parameters
path (pathlib.Path) – path where the model will be saved
filename (str) – filename of the model