Trainer, which you may already be familiar with if you have worked with other machine learning libraries (e.g. scikit-learn) before. A Trainer has two important methods:
fit(), which takes aGraphandTrainingTable(or aTrainingTableJob, if the training table was generated in a non-blocking manner), and trains a model on this graph and training table.predict(), which takes aGraphandPredictionTable(or aPredictionTableJob, if the prediction table was generated in a non-blocking manner), a job ID corresponding to a trained model, and other parameters detailing where to output the predictions. It generates predictions for each entity in the prediction table, and writes the outputs to the specified output connector.
Training a model is fully customizable, with a detailed suite of model plan options. For a guide on tuning your model for optimal performance, see here.
You can view all your launched jobs in the Kumo UI, at the URL
https://<customer_id>.kumoai.cloud/jobs. Jobs are keyed by their unique job ID, and contain all specified job tags as well.How do I create a Trainer? What’s a model plan?
Creating aTrainer object requires a model plan, which defines the search space to be used when exploring model configurations for model training.
You can suggest a model plan for your predictive query with suggest_model_plan(), which will produce an object of type `ModelPlan`:
ModelPlan object for the exposed customizable attributes.
Once you have customized your model plan to your liking, you can create a Trainer by simply passing the model plan in:
How do I train a model?
Training a model amounts to callingfit(), which accepts the following arguments:
- A
Graph, which defines the data that the model will be trained on. Note if you have already calledsnapshot(), this snapshot of the data will be used when training your model. - A
TrainingTableorTrainingTableJob, generated bygenerate_training_table(). This defines the training examples that will be used by the model; if aTrainingTableJobis passed, its execution will be sequenced before training by the Kumo platform. non_blocking, which can be set toTrueif you would like to schedule training and return immediately, orFalseif you would like to wait for training to complete.custom_tags, which define a custom mapping of key/value tags that you can use to label your training job.
TrainingJobResult if non_blocking=False and training completes successfully, or a TrainingJob if non_blocking=True. Each training job is associated with a unique Job ID, starting with trainingjob-.
An example invocation of fit() is as follows:
How do I view the metrics and artifacts of a trained model?
Recall that a trained model is represented by aTrainingJobResult object; if you have a TrainingJob, you need to await its completion by calling result() before proceeding.
A TrainingJobResult exposes numerous methods to help analyze the performance of a trained model, including metrics() and holdout_df(). A full set of visualizations, performance graphs, and explainability can all be accessed at the URL specified by :py`tracking_url`.
How do I generate predictions?
Predicting on a trained model amounts to callingpredict(), which accepts the following arguments:
- A
Graph, which defines the data that the model will use to make predictions on. Note if you have already calledsnapshot(), this snapshot of the data will be used when generating predictions. - A
PredictionTableorPredictionTableJob, generated bygenerate_prediction_table()or supplied via a custom path. This defines the prediction examples that will be used by the model; if aPredictionTableJobis passed, its execution will be sequenced before prediction by the Kumo platform. training_job_id, which defines the job ID of the training job whose model will be used for making predictions.non_blocking, which can be set toTrueif you would like to schedule prediction and return immediately, orFalseif you would like to wait for prediction to complete.custom_tags, which define a custom mapping of key/value tags that you can use to label your training job.- additional arguments documented in
predict()that can be used to specify where predictions should be output to.
TrainingJobResult if non_blocking=False and training completes successfully, or a TrainingJob if non_blocking=True. Each batch prediction job is associated with a unique Job ID, starting with bp-job-.
An example invocation of predict() is as follows:
How do I poll a training or prediction job’s status?
Any job scheduled withnon_blocking=True will be represented as a Future object, that has various methods to poll the scheduled job for its status or completion. Common patterns include:
- Querying
future.status()for the status of the scheduled job in a loop - Calling
future.attach()to attach to the future and print logs periodically; when the future is complete, this method will return the resolved output (e.g.TrainingJobbecomesTrainingJobResult) - Calling
future.result()will block until the future is complete, and return the resolved output.