model.py#
- class mlui.classes.model.Model[source]#
Bases:
object
Class representing a machine learning model.
This class provides methods for managing and interacting with a TensorFlow machine learning model.
- reset_state()[source]#
Reset the model state.
This method resets the internal state of the model, including its configuration and assigned features.
- update_state()[source]#
Update the internal state of the model, resetting the input and output features.
- _shapes_to_list(shapes)[source]#
Convert shapes from a dictionary or a single tuple to a list.
- Parameters:
shapes (dict of tuples, list of tuples or tuple) – Input or output shapes. Single shape is a tuple of (None, int).
- Returns:
Converted shapes.
- Return type:
list of tuples
- _get_processed_shape(at)[source]#
Retrieve and process the shapes of input or output layers.
- Parameters:
at ({'input', 'output'}) – Side to retrieve shapes for.
- Returns:
Processed shapes for the specified side.
- Return type:
dict of {str to int}
- _get_processed_data(data, at)[source]#
Process the input or output data based on the specified side.
- Parameters:
data (DataFrame) – Input or output data.
at ({'input', 'output'}) – Side to process data for.
- Returns:
Processed data.
- Return type:
dict of {str to NDArray}
- set_optimizer(entity, params)[source]#
Set the optimizer for the model.
- Parameters:
entity (str) – Name of the optimizer type.
params (OptimizerParams) – Parameters for the optimizer.
- Raises:
SetError – If there is an issue setting the optimizer.
- get_optimizer()[source]#
Get the name of the current optimizer.
- Returns:
Name of the optimizer.
- Return type:
str or None
- set_loss(layer, entity)[source]#
Set the loss function for a specific output layer.
- Parameters:
layer (str) – Name of the output layer.
entity (str) – Name of the loss function type.
- get_loss(layer)[source]#
Get the loss function for a specific output layer.
- Parameters:
layer (str) – Name of the output layer.
- Returns:
Name of the loss function.
- Return type:
str or None
- set_metrics(layer, entities)[source]#
Set the metrics for a specific output layer.
- Parameters:
layer (str) – Name of the output layer.
entities (list of str) – Names of the metrics.
- get_metrics(layer)[source]#
Get the metrics for a specific output layer.
- Parameters:
layer (str) – Name of the output layer.
- Returns:
Names of the metrics.
- Return type:
list of str
- compile()[source]#
Compile the model.
- Raises:
ModelError – If there is an issue compiling the model.
- set_features(layer, columns, at)[source]#
Set the input or output features for a specific layer.
- Parameters:
layer (str) – Name of the layer.
columns (list of str) – Names of the columns.
at ({'input', 'output'}) – Side to set features for.
- Raises:
SetError – If there is an issue setting the features.
- get_features(layer, at)[source]#
Get the input or output features for a specific layer.
- Parameters:
layer (str) – Name of the layer.
at ({'input', 'output'}) – Side to get features for.
- Returns:
Names of the features.
- Return type:
list of str
- set_callback(entity, params)[source]#
Set the callback for the model.
- Parameters:
entity (str) – Name of the callback type.
params (CallbackParams) – Parameters for the callback.
- Raises:
SetError – If there is an issue setting the callback.
- get_callback(entity)[source]#
Get the callback for the model.
- Parameters:
entity (str) – Name of the callback type.
- Returns:
Callback instance.
- Return type:
Callback or None
- delete_callback(entity)[source]#
Delete the callback from the model.
- Parameters:
entity (str) – Name of the callback type.
- fit(data, batch_size, num_epochs, val_split)[source]#
Fit the model to the provided data.
- Parameters:
data (DataFrame) – Input and output data.
batch_size (int) – Batch size.
num_epochs (int) – Number of epochs.
val_split (float) – Validation split.
- Raises:
ModelError – If there is an issue fitting the model.
- _update_history(logs)[source]#
Update the training history with new logs.
- Parameters:
logs (DataFrame) – New logs to be added to the history.
- plot_history(y, points)[source]#
Plot the training history.
- Parameters:
y (list of str) – Names of the logs to plot.
points (bool) – Whether to include points on the plot.
- Returns:
Altair chart representing the training history.
- Return type:
Chart
- property name: str#
Name of the model.
- property inputs: list[str]#
Names of the input layers.
- property outputs: list[str]#
Names of the output layers.
- property input_shape: dict[str, int]#
Shapes of the input layers.
- property output_shape: dict[str, int]#
Shapes of the output layers.
- property input_configured: bool#
True if all input layers are configured, False otherwise.
- property output_configured: bool#
True if all output layers are configured, False otherwise.
- property built: bool#
True if the model is built, False otherwise.
- property compiled: bool#
True if the model is compiled, False otherwise.
- property history: DataFrame#
Training history DataFrame.
- property summary: None#
Summary of the model.
- property graph: bytes#
Bytes representation of the model graph.
- property as_bytes: bytes#
Bytes representation of the saved model.
- class mlui.classes.model.UploadedModel[source]#
Bases:
Model
Class representing the uploaded model.
- upload(buff)[source]#
Upload a model from the provided file.
- Parameters:
buff (file-like object) – Byte buffer containing the model.
- Raises:
UploadError – If there is an issue reading the model from the file. If there is an issue validating the shapes of the model.
- evaluate(data, batch_size)[source]#
Evaluate the model on the provided data.
- Parameters:
data (DataFrame) – Input and output data.
batch_size (int) – Batch size.
- Raises:
ModelError – If there is an issue evaluating the model.
- Returns:
Evaluation results as a DataFrame.
- Return type:
DataFrame
- predict(data, batch_size)[source]#
Make predictions using the model on the provided data.
- Parameters:
data (DataFrame) – Input data.
batch_size (int) – Batch size.
- Raises:
ModelError – If there is an issue making predictions.
- Returns:
Predictions as DataFrames.
- Return type:
list of DataFrame
- class mlui.classes.model.CreatedModel[source]#
Bases:
Model
Class representing the created model.
- set_name(name)[source]#
Set the name of the created model.
- Parameters:
name (str) – Name of the model.
- set_layer(entity, name, params, connection)[source]#
Set the layer for the created model.
- Parameters:
entity (str) – Name of the layer type.
name (str) – Name of the layer.
params (LayerParams) – Parameters for the layer.
connection (Layer, list of Layer or None) – Layer(s) to connect.
- Raises:
SetError – If there is an issue setting the layer.
- delete_last_layer()[source]#
Delete the last layer from the created model.
- Raises:
DeleteError – If there are no layers to remove.
- set_outputs(outputs)[source]#
Set the output layers for the created model.
- Parameters:
outputs (list of str) – Names of the layers.
- Raises:
SetError – If there is an issue setting the output layers.
- create()[source]#
Create the machine learning model.
- Raises:
CreateError – If there is an issue creating the model.
- property layers: dict[str, Layer]#
Objects of the layers.