Python Learner (Python Scripting)
Synopsis
This operator generates a Python model that is compatible with Altair AI Studio's model interfaces.Description
The Python Learner operator enables you to create custom predictive models using Python scripts within Altair AI Studio. Depending on the operator's configuration, you can edit the Python script to define the model's training and application logic according to your specific needs.
If the operator is editable, the parameter panel includes buttons at the top of the parameter list that allow you to:
- **Edit the Operator Declaration**: Customize capabilities, parameter types, and input and output ports.
- **Edit the Python Script**: Modify the script that trains and applies your model.
- **Save as Template**: Save your configuration for future use.
You can define user-configurable parameters to make your operator more flexible. To create a new parameter, extend the editable JSON parameters array by adding a new JSON object like the following: { "name": "my_new_parameter", "description": "This parameter adjusts the regularization strength.", "type": "real", "optional": false, "value": 0.1 }
Similarly, you can define user-configurable input ports. To create a new input port, extend the editable JSON inputs array by adding a new JSON object: { "name": "additional_data", "type": "table" }
You can also define user-configurable output ports. To create a new output port, extend the editable JSON outputs array by adding a new JSON object: { "name": "performance", "type": "table" }
If the operator is not editable, you can check the operator capabilities to learn more about the inputs supported by the preconfigured Python script.
Please note that the model generated by this operator wraps the Python model returned by your Python script. Both training and applying the model require a compatible Python environment.
Input
- training set (Data table)
The input data which is used to generate the Python model.
Output
- model (Model)
The wrapped Python model is output from this port.
- example set (Data table)
The input example set is passed through to this output port unchanged.
Parameters
- operator If enabled, this parameter allows to edit the operator declaration (such as capabilities, parameter types, and ports) and the Python script used to train and apply the Python model.
Tutorial Processes
Classification and regression in a single Python Learner
This example shows how to create a single Python Learner, that supports both classification and regression, and can handle nominal features. In other words, a Python Leaner that behaves very similar to Altair AI Studio's builtin learners.
The example wraps the popular LightGBM models and uses Scikit-learn's pipeline concept to create a learner that automatically one-hot encodes all non-numeric features and checks the type of the target variable to decide whether to train a classifier of regressor.
Unsupervised learning
This tutorial process shows how to create an unsupervised Python Learner by the example of wrapping Scikit-learn's Isolation Forest. A Scikit-learn pipeline including one-hot encoding is used to support nominal features.