actableai.utils.resources.predict package

Submodules

actableai.utils.resources.predict.models module

actableai.utils.resources.predict.models.create_pipeline(resource_predicted: actableai.utils.resources.predict.ResourcePredictorType, task: actableai.tasks.TaskType) Optional[actableai.utils.river.MultiOutputPipeline]

Create a pipeline (model) for resource prediction

Parameters
  • resource_predicted – The resource to predict
  • task – The task to predict for
Return type

The river pipeline to use for prediction or None if not available

actableai.utils.resources.predict.predictor module

class actableai.utils.resources.predict.predictor.ResourcesPredictorsActor(s3_resources_predictors_bucket: Optional[str] = None, s3_resources_predictors_prefix: Optional[str] = None, resources_predictors_data_path: Optional[str] = None, random_state: Optional[int] = None, backup_state_probability: Optional[float] = None, override_models: bool = False)

Bases: object

Class used to store different resources predictors Is is assumed that this class will be used as a ray Actor

add_data(resource_predicted: actableai.utils.resources.predict.ResourcePredictorType, task: actableai.tasks.TaskType, features: dict, target: float, prediction: Optional[float] = None, timestamp: Optional[int] = None, full_features: Optional[dict] = None)

Add data to the prediction model (train)

Will backup the resources predictors data to either AWS S3 or the filesystem with the pre-defined probability

Parameters
  • resource_predicted – The resource to predict
  • task – The task to predict for
  • features – The features to train the model with
  • target – The observed value to train with (ground truth)
  • prediction – The predicted value with these features before training (if None will be re-computed)
  • timestamp – The timestamp used for backup-ing the data, current timestamp by default
  • full_features – All the collected features, these are not used to train the model, just to keep track of everything to eventually add new features in the future
classmethod get_actor(s3_resources_predictors_bucket: Optional[str] = None, s3_resources_predictors_prefix: Optional[str] = None, resources_predictors_data_path: Optional[str] = None, random_state: Optional[int] = None, backup_state_probability: Optional[float] = None) ray.actor.ActorHandle

Get the ray Actor, will create it if it does not exist already

Parameters
  • s3_resources_predictors_bucket – The AWS S3 bucket name where the resources predictors data are stored
  • s3_resources_predictors_prefix – The AWS S3 prefix to use when fetching the resources predictors data
  • resources_predictors_data_path – The path where the resources predictors data are located, this will be used only if the S3 AWS parameters are None
  • random_state – The random state to use for the random generator, if None will use the current timestamp
  • backup_state_probability – The probability to start a backup of the resources predictors data when calling the add_data method, default: 0.1 (10%)
Return type

The Actor Handle

async get_model_metrics(resource_predicted: actableai.utils.resources.predict.ResourcePredictorType, task: actableai.tasks.TaskType) Dict[str, float]

Get the metrics of one specific model

Parameters
  • resource_predicted – The resource to predict
  • task – The task to predict for
Return type

Dictionary with the metrics names as a key and the metrics values as value

classmethod migrate(s3_bucket: str, s3_prefix_list: List[str])

Update models and backup old training data

Here is how to call this function: `python from actableai.utils.resources.predict.predictor import ResourcesPredictorsActor ResourcesPredictorsActor.migrate("actable-ai-resources-predictors", ["dev"]) `

In this example we are migrating the dev folder, but you can replace it by prod or even update both at the same time.

How it works? This function will create a backup folder and will move every models, model metrics, and training data already existing in this backup folder. Once this is done it will create brand new pipelines and will train each of these pipelines using the training data collected previously and uploaded in AWS. Finally it will save these new pipelines overriding the previous ones (which are backed up).

Parameters
  • s3_bucket – The AWS S3 bucket name where the resources predictors data are stored
  • s3_prefix_list – The list of AWS S3 prefix to use when fetching the resources predictors data
async predict(resource_predicted: actableai.utils.resources.predict.ResourcePredictorType, task: actableai.tasks.TaskType, features: dict) float

Make a prediction for a resource usage

Parameters
  • resource_predicted – The resource to predict
  • task – The task to predict for
  • features – The features to feed the model with
Return type

The predicted value

Module contents

class actableai.utils.resources.predict.ResourcePredictorType(value)

Bases: str, enum.Enum

Enum representing the different type of resource that are predictable

MAX_GPU_MEMORY = 'max_gpu_memory'
MAX_MEMORY = 'max_memory'