With this plugin, you can train machine learning models and then use them to score new records, all within your Snowflake environment. This no-code UI allows data scientists and domain experts to quickly train models, track experiments, and visualize model performance.
- No-code ML model training on Snowpark using Snowflake’s snowflake-ml-python package
- Two-class classification, multi-class classification, and regression tasks on tabular data stored in a Snowflake table
- Hyperparameter tuning using Random Search on certain algorithm parameters
- Track hyperparameter tuning and model performance through Dataiku’s Experiment Tracking MLflow integration
- Output the best trained model to a Dataiku Saved Model in the flow, and deploy the model to a Snowflake Model Registry
- No-code ML batch scoring in Snowpark using a trained model (from the training recipe of this plugin)
- Macro to clean up models from the Snowflake Model Registry that have been deleted from the Dataiku project
- If doing two-class or multi-class classification, convert your target column to numeric (0,1) or (0, 1, 2, 3, 4) before using this plugin (this is a SnowparkML requirement)
- No int type columns can have missing values. If you have an int column with missing values, convert the type to double before this recipe (this is an MLflow requirement)
- If you want to treat a numeric column as categorical, change its storage type to string in a prior recipe
- Must have a Snowflake connection. Plugin recipe Input + Output tables should be in the same Snowflake connection
- The Snowflake role used must either own the schema where the Input + Output tables live, or have the CREATE MODEL privilege on it
- Python 3.9 available on the instance
- (Strongly recommended) Snowpark-optimized Snowflake warehouse available for model training. Multi-cluster warehouse will allow for parallelized hyperparameter tuning
Right after installing the plugin, you will need to build its code environment. Note that this plugin requires Python version 3.9 and that conda is not supported.
Name it “py_39_snowpark” Under “Core packages versions”, choose Pandas 1.3 Add these packages, then update the environment:
scikit-learn==1.3.0
mlflow==2.9.2
statsmodels==0.12.2
protobuf==3.16.0
xgboost==1.7.3
lightgbm==3.3.5
matplotlib==3.7.1
scipy==1.10.1
snowflake-snowpark-python==1.19.0
snowflake-snowpark-python[pandas]==1.19.0
snowflake-connector-python[pandas]==3.11.0
MarkupSafe==2.0.1
cloudpickle==2.0.0
flask==1.0.4
Jinja2==2.11.3
snowflake-ml-python==1.5.4
Click once on the input dataset (with known, labeled target values), then find the Visual SnowparkML plugin:
Click the train recipe:
![image](https://private-user-images.githubusercontent.com/22987725/330797443-315ddd8c-ce08-4fdc-9dc3-b1223e4d3f09.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQyNzY0MjQsIm5iZiI6MTcyNDI3NjEyNCwicGF0aCI6Ii8yMjk4NzcyNS8zMzA3OTc0NDMtMzE1ZGRkOGMtY2UwOC00ZmRjLTlkYzMtYjEyMjNlNGQzZjA5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODIxVDIxMzUyNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTM4NWNiMWI2MTFkYTg3MWM0MmQxODMwNTJjMTFiNmVlYmIyMGI4NDlkY2JmYzgyZmYyOWY0MTI5NGUyNDU2MjEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.IgqGg6VgFr-5_sMBRQKKaEunS5p66tbAd4mTo99VCWY)
Create two output Snowflake tables to hold the generated output train/test sets, and one managed folder to hold saved models (connection doesn’t matter):
Make sure you fill out all required fields Below is an example for a two-class classification problem: Parameters
- Final model name: the name of your model
- Target column: the name of your target column to predict
- Prediction type: either two-class classification or regression
- Disable class weights: choose to disable class weights (not recommended). Class weights are row weights that are inversely proportional to the cardinality of its target class and help with class imbalance issues
- Train ratio: train set / test set ratio. 0.8 is a good start
- Random seed: Set this (to any integer) to maintain consistent train/test sets over multiple training runs
- Enable time ordering: order the train and test sets by a datetime column (test set will be more recent timestamps than train set)
- Metrics: metric to optimize model performance
Features selection When you include a feature, don't leave the "Encoding / Rescaling" and "Impute Missing Values With" dropdowns empty!
- Type: underlying storage type. Note: if you want to treat a numeric column as categorical, change its storage type to string in a prior recipe
- Include: whether to include the column in the model
- Encoding / Rescaling: choose how to encode categorical features, and rescale numeric features.
- Impute Missing Values With: choose how to deal with missing values
- Constant Value (Impute): if “Constant” chosen for missingness imputation, the value to impute
Algorithms
- Select each algorithm you’d like to train
- For each algorithm, enter min and max values for each hyperparameter
- Enter a search space limit (randomly choose N hyperparameter combinations for each algorithm within the min/max values chosen)
- A Snowpark ML Randomized Search with 3-fold cross-validation will kick off in Snowflake to find the best hyperparameter combination for each algorithm
Snowflake Resources and Deployment
- Snowflake Warehouse: the warehouse to use for ML training. Strongly recommended to use a Snowpark-optimized Snowflake warehouse. A multi-cluster warehouse will allow for parallelized hyperparameter tuning.
- Deploy to Snowflake ML Model Registry: deploy the best trained model to a Snowflake ML Model Registry (in the same database and schema as the input and output datasets. See Snowflake access requirements here. This is required in order to run a subsequent Visual Snowpark ML Score recipe, to run batch inference in Snowpark using the deployed model.
After running the train recipe successfully, you can find all model training and hyperparameter tuning information, including model performance metrics in Dataiku’s Experiment Tracking tab
The best model will be deployed to the flow. If you selected “Deploy to Snowflake ML Model Registry”, the model will also be deployed to Snowflake’s Model Registry.
![Screenshot 2024-05-15 at 8 09 47 AM](https://private-user-images.githubusercontent.com/22987725/330797922-5e7837da-60db-4814-afc6-6389fef71100.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQyNzY0MjQsIm5iZiI6MTcyNDI3NjEyNCwicGF0aCI6Ii8yMjk4NzcyNS8zMzA3OTc5MjItNWU3ODM3ZGEtNjBkYi00ODE0LWFmYzYtNjM4OWZlZjcxMTAwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODIxVDIxMzUyNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWFjYzRkYzcxN2Q4YzgwYzc1ZmIwNmZiMTc2ZWMwMmZhNmM3N2IxNDg4NzNhYmE1MWFjYmFmYjdiZDY5NDE0ZDgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.9faKa2XaVZp6f-xvu1GlkSyX_u1DijopUi-Hp6It7qM)
Note: you can use a regular Dataiku Score recipe with the Snowpark ML trained model, however, the inference will happen in a local python kernel, and not in Snowflake. Note that for classification models where you did NOT disable class weights, you'll need to add a SAMPLE_WEIGHTS column in your input dataset before a regular Dataiku Score recipe (this column can have all empty values).
In order to run batch inference in Snowpark, use this plugin's Visual Snowpark ML Score recipe. You must have checked “Deploy to Snowflake ML Model Registry” when training the model for this to work.
Click once on the trained model and input dataset you’d like to make predictions for:
Click the score recipe:
![image](https://private-user-images.githubusercontent.com/22987725/330798474-85ff1459-8dc3-485c-981f-20c84bc51de7.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQyNzY0MjQsIm5iZiI6MTcyNDI3NjEyNCwicGF0aCI6Ii8yMjk4NzcyNS8zMzA3OTg0NzQtODVmZjE0NTktOGRjMy00ODVjLTk4MWYtMjBjODRiYzUxZGU3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODIxVDIxMzUyNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQyNDhmMDczNTg4NzRjOTc4ODM1MDAzNDliOWIzYmUxOTRhY2Q0MDYyY2Y4OGE1N2RjODI5ZjFhZWFiZmE5MmYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.Bh3mzg8QaL8oFWEpGyrZG0xvxSNYi_nAGi6z2obXdl4)
Make sure you’ve selected the trained model and Snowflake table for scoring as inputs. Then create one output Snowflake table to hold the scored dataset. Then click “Create”:
Optionally type the name of a Snowpark-optimized Snowflake warehouse to use for scoring. Leave empty to use the Snowflake connection’s default warehouse. Note: it’s less needed to use a Snowpark-optimized warehouse for inference compared to training. Click “Run”.
Your flow should look like this, and the output scored dataset should have prediction column(s):
![Screenshot 2024-05-14 at 4 21 17 PM](https://private-user-images.githubusercontent.com/22987725/330799185-a93839ac-490d-4bc8-bc6d-03ca841c80a8.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQyNzY0MjQsIm5iZiI6MTcyNDI3NjEyNCwicGF0aCI6Ii8yMjk4NzcyNS8zMzA3OTkxODUtYTkzODM5YWMtNDkwZC00YmM4LWJjNmQtMDNjYTg0MWM4MGE4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODIxVDIxMzUyNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWY4MDI3MmM5ZmJiNTc0NTFhYTkwYWM2ZGM1NGU5ZDZhMjRjYTZjNjRlMTQxOTdhM2E1ODg3MGI3NzY2ODk2NTEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.zq4ISJNpEMcP2yBxxX55zyoFlwuww4rzJwPxa202bAk)
When deploying trained models to a Snowflake Model Registry, we want to ensure that any trained models that we delete from the Dataiku UI (by deleting a full green diamond saved model, or a saved model version underneath), are also deleted from the Snowflake Model Registry.
This macro checks for any models in the Snowflake Model Registry that have the Dataiku and the current project key tags; if the model has been deleted from the Dataiku project, this macro deletes the model from the Snowflake Model Registry.
You can list the models the macro would delete by un-checking the “Perform deletion” box.
The macro will show the model name and version deleted (or simulated) in the resulting list.
![image](https://private-user-images.githubusercontent.com/22987725/307417519-0e5594ec-8bd2-41a2-8aa8-aba3386240d0.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQyNzY0MjQsIm5iZiI6MTcyNDI3NjEyNCwicGF0aCI6Ii8yMjk4NzcyNS8zMDc0MTc1MTktMGU1NTk0ZWMtOGJkMi00MWEyLThhYTgtYWJhMzM4NjI0MGQwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODIxVDIxMzUyNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTVlMWU0NjQ4ODc3ZGUzMzQ4OTMzZTk5NWU4MGFhMzU5OTBiNjlmZDU5NzJhYTUzZDk0YzllZDYzNjAwZDMyMDMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.iOQ30BTrL_ufn3bak5uW5Txn5s7M-MSckwIvmXbL8h0)
![image](https://private-user-images.githubusercontent.com/22987725/307417625-7b857a57-fc0d-4408-8ed0-70598ac36e66.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQyNzY0MjQsIm5iZiI6MTcyNDI3NjEyNCwicGF0aCI6Ii8yMjk4NzcyNS8zMDc0MTc2MjUtN2I4NTdhNTctZmMwZC00NDA4LThlZDAtNzA1OThhYzM2ZTY2LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODIxVDIxMzUyNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWEyYmM5MDhlZTU1ZGE2OTcxOGYxZjVlMDJlMTkyODlhYzc5Yjg0NmRmMDQ2MjZiMWMzNTM3NGZmYzA3N2NjYTEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.DZtlFuZ_DOY2ZkXmCOBPrFAPak_XkmtQriHvWTd8L7Y)
![Screenshot 2024-02-23 at 12 51 50 PM](https://private-user-images.githubusercontent.com/22987725/307417668-7e2cd3bd-0561-424a-a68d-50608f3ed770.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQyNzY0MjQsIm5iZiI6MTcyNDI3NjEyNCwicGF0aCI6Ii8yMjk4NzcyNS8zMDc0MTc2NjgtN2UyY2QzYmQtMDU2MS00MjRhLWE2OGQtNTA2MDhmM2VkNzcwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODIxVDIxMzUyNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWEzY2ZlNzA2ZDExYjM0ODk1N2ZhMzczNDlmNjdiNDVmN2Q2YTg1MjNhMWU4NmRmMTc0NTE5M2JjMmZkZjc1NzEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.WW1CxLVl-qZRMUAReL7EzcZ4_xMnYPZEJjh-vR43XyU)
![Screenshot 2024-02-23 at 12 52 30 PM](https://private-user-images.githubusercontent.com/22987725/307417700-d27a4ec8-9a52-430b-9c06-936ede71f33c.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQyNzY0MjQsIm5iZiI6MTcyNDI3NjEyNCwicGF0aCI6Ii8yMjk4NzcyNS8zMDc0MTc3MDAtZDI3YTRlYzgtOWE1Mi00MzBiLTljMDYtOTM2ZWRlNzFmMzNjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODIxVDIxMzUyNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTgzNzMwYjk1MTJjNDAxNmQxMDJlODEwNjlhMThlYjZiNWMwNGQ4N2UwYmFkMzRkMzdkNjA3MjRiOTFjY2FhYTkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.eujXJRsIxkJ7A-oh9QqRa_uPGZ5ZxBccXK9feOkV7JU)
See the changelog for a history of notable changes to this plugin.
This plugin is distributed under the Apache License version 2.0.