Snowflake Notebooks for ML Development
Snowflake Notebooks provide an interactive development environment directly within Snowsight. They combine SQL and Python cells in a single document, giving data scientists a familiar notebook experience without leaving the Snowflake platform.
What Are Snowflake Notebooks?
Snowflake Notebooks are browser-based notebooks that run on Snowflake compute. They support SQL, Python, and Markdown cells and integrate natively with Snowflake data, warehouses, and the Snowpark runtime.
| Feature | Description |
|---|---|
| Multi-language cells | SQL, Python, and Markdown in one notebook |
| Snowflake-native | Runs on warehouse or Snowpark-optimized compute |
| Built-in packages | Pre-installed Snowpark, pandas, matplotlib, scikit-learn |
| Git integration | Version notebooks through Snowflake Git repositories |
| Collaboration | Share notebooks with roles and teams |
Creating a Notebook
- Open Snowsight and navigate to Projects > Notebooks.
- Click + Notebook.
- Select a database, schema, and warehouse for execution context.
- Choose a compute option: standard warehouse or Snowpark-optimized warehouse for heavier ML workloads.
SQL and Python Cells
SQL Cell
SQL cells execute against the notebook's warehouse and return results inline.
-- SQL Cell
SELECT CUSTOMER_ID, INCOME, BALANCE, CHURN_FLAG
FROM ML_DB.PUBLIC.CUSTOMERS
LIMIT 100;
Python Cell
Python cells run in a managed Snowpark environment. Access SQL cell results using the cell name.
# Python Cell
import snowflake.snowpark.functions as F
# Reference the active session (automatically available)
df = session.table("ML_DB.PUBLIC.CUSTOMERS")
print(f"Row count: {df.count()}")
# Access SQL cell output by cell name
sql_result = cell1.to_pandas()
print(sql_result.head())
Markdown Cell
Use Markdown cells for documentation, section headers, and notes within the notebook.
Connecting to a Warehouse
The notebook session inherits the warehouse selected at creation. Switch warehouses within a Python cell if needed.
session.use_warehouse("ML_WH_LARGE")
For GPU workloads (deep learning, large model training), select a Snowpark-optimized warehouse with GPU support when creating the notebook.
Importing Libraries
Common ML libraries are pre-installed. Install additional packages from the Snowflake Anaconda channel.
# Pre-installed — import directly
import pandas as pd
import numpy as np
from sklearn.ensemble import GradientBoostingClassifier
from snowflake.ml.modeling.preprocessing import StandardScaler
# Install additional packages via the Packages panel
# Click the Packages button in the notebook toolbar
# Search and add packages like xgboost, lightgbm, shap
Visualizations
Snowflake Notebooks support inline visualizations using standard Python libraries.
import matplotlib.pyplot as plt
pdf = df.select("AGE", "INCOME").to_pandas()
fig, ax = plt.subplots(1, 2, figsize=(12, 4))
ax[0].hist(pdf["AGE"], bins=30, edgecolor="black")
ax[0].set_title("Age Distribution")
ax[1].scatter(pdf["AGE"], pdf["INCOME"], alpha=0.3)
ax[1].set_title("Age vs Income")
plt.tight_layout()
plt.show()
SQL cell results also have a built-in chart view — click the Chart tab above results to configure bar, line, and scatter plots without code.
Running ML Experiments in Notebooks
A typical ML experiment flow in a Snowflake Notebook:
# Cell 1 — Load and explore
df = session.table("ML_DB.PUBLIC.CUSTOMERS")
df.describe().show()
# Cell 2 — Preprocess
from snowflake.ml.modeling.preprocessing import StandardScaler
train_df, test_df = df.random_split([0.8, 0.2], seed=42)
scaler = StandardScaler(
input_cols=["INCOME", "BALANCE"],
output_cols=["INCOME_S", "BALANCE_S"]
)
scaler.fit(train_df)
train_scaled = scaler.transform(train_df)
test_scaled = scaler.transform(test_df)
# Cell 3 — Train
from snowflake.ml.modeling.ensemble import RandomForestClassifier
model = RandomForestClassifier(
input_cols=["INCOME_S", "BALANCE_S", "TENURE_MONTHS"],
label_cols=["CHURN_FLAG"],
output_cols=["PREDICTION"]
)
model.fit(train_scaled)
# Cell 4 — Evaluate
from snowflake.ml.modeling.metrics import accuracy_score
predictions = model.predict(test_scaled)
acc = accuracy_score(
df=predictions,
y_true_col_names=["CHURN_FLAG"],
y_pred_col_names=["PREDICTION"]
)
print(f"Accuracy: {acc:.4f}")
# Cell 5 — Log to Registry
from snowflake.ml.registry import Registry
reg = Registry(session=session, database_name="ML_DB", schema_name="REGISTRY")
reg.log_model(
model_name="churn_nb_model",
version_name="v1",
model=model,
comment="Trained in notebook experiment"
)
Collaboration Features
| Feature | How to Use |
|---|---|
| Share with role | Grant USAGE on the notebook to a role |
| Git sync | Connect to a Snowflake Git repository for version control |
| Schedule | Run notebooks on a schedule via Tasks |
| Export | Download as .ipynb for local use |
Best Practices for Notebook-Based ML
- Use Markdown cells liberally — document hypotheses, findings, and decisions inline.
- Keep cells focused — one logical step per cell (load, preprocess, train, evaluate).
- Parameterize — use variables for table names and hyperparameters so experiments are easy to rerun.
- Version with Git — connect the notebook to a Git repo to track changes over time.
- Log models to the Registry — do not rely on notebook state for model persistence.
- Clean up — drop temporary tables and stages created during experimentation.
- Right-size compute — use a standard warehouse for exploration and scale up only for training.
Key Takeaways
- Snowflake Notebooks provide a zero-setup, browser-based ML development environment.
- Mix SQL for data exploration with Python for modeling in a single document.
- Visualize results inline with matplotlib or the built-in chart view.
- Combine notebooks with the Model Registry and Feature Store for a complete ML workflow inside Snowflake.