agentleFS
Google CloudKnown publisherGoogleCloudPlatform/cloud-solutions/projects/legacy-detox-demo/skills/bigframes-bqml/SKILL.md

bigframes-bqml

Skill138 starsChanged 5 months agoApache-2.0View on GitHub

This skill defines the "data-resident ML" approach using BigQuery DataFrames (BigFrames). It allows data scientists to perform feature engineering and model training directly inside BigQuery using a pythonic API (bigframes.pandas and bigframes.ml), eliminating data egress. - Python Package: bigframes (includes bigframes.pandas and bigframes.ml). - BigQuery: Access to a BigQuery dataset for saving models and tables. When developing BigQuery-centric pipelines: 1. Prefer Python API: Use bigframes.pandas for data manipulation and bigframes.ml for machine learning, rather than raw SQL, to maintain a…

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 2 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When developing BigQuery-centric pipelines:

    line 24
  2. Very specific:

    Prefer Python API: Use bigframes.pandas for data manipulation and bigframes.ml for machine learning, rather than raw SQL, to maintain a …

    line 26
  3. Very specific:

    Zero Egress: Do not call .to_pandas() on large BigFrames, as this pulls data locally.

    line 29
  4. Distinctive:

    Use pandas-like operations that compile to SQL.

    line 39

≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Skill: BigFrames & Warehouse-Resident ML (BQML)

<!-- Disabling markdownlint MD029 to provide explicit ordering to avoid confusing the LLM. --><!-- markdownlint-disable MD029 -->

1. Description & Rationale

This skill defines the "data-resident ML" approach using BigQuery DataFrames (BigFrames). It allows data scientists to perform feature engineering and model training directly inside BigQuery using a pythonic API (bigframes.pandas and bigframes.ml), eliminating data egress.

2. Environment Prerequisites

  • Python Package: bigframes (includes bigframes.pandas and bigframes.ml).
  • BigQuery: Access to a BigQuery dataset for saving models and tables.

3. Agent Execution Guidelines (System Prompts)

When developing BigQuery-centric pipelines:

  1. Prefer Python API: Use bigframes.pandas for data manipulation and bigframes.ml for machine learning, rather than raw SQL, to maintain a consistent Python experience.
  2. Zero Egress: Do not call .to_pandas() on large BigFrames, as this pulls data locally. Keep computations in the cloud.
  3. Automatic Preprocessing: Leverage BQML's automatic one-hot encoding for categorical variables (like country/gender) and standardization for numerical variables, avoiding complex manual preprocessing pipelines.

4. Opinionated Code Patterns

A. Feature Engineering with BigFrames

Use pandas-like operations that compile to SQL.

# Filter, join, and deduplicate natively in BigQuery
complete_orders = order_items_df[order_items_df["status"] == "Complete"]

user_orders = complete_orders.merge(
    users_df, left_on="user_id", right_on="id", suffixes=("_order", "_user")
)

merged_df = user_orders.merge(
    products_df, left_on="product_id", right_on="id", suffixes=("", "_product")
)

# Identify the most recent purchase per user
sorted_df = merged_df.sort_values("created_at_order", ascending=False)
latest_purchases = sorted_df.drop_duplicates(subset=["user_id"], keep="first")

# Select features and label
training_data = latest_purchases[
    ["user_id", "age", "gender", "country", "category"]
].rename(columns={"category": "label_category"})

training_data["age"] = training_data["age"].astype("Float64")

B. Training BQML Models via BigFrames ML

Train models natively in BigQuery using scikit-learn-like syntax.

from bigframes.ml.linear_model import LogisticRegression
from bigframes.ml.model_selection import train_test_split

# Split features and label
X = training_data[["age", "gender", "country"]]
y = training_data[["label_category"]]

X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.2, random_state=42
)

# Initialize and train the model (executes in BigQuery)
model = LogisticRegression()
model.fit(X_train, y_train)

# Save the model natively to a BigQuery dataset
MODEL_NAME = f"{PROJECT_ID}.reengagement.bq_product_affinity_model"
model.to_gbq(MODEL_NAME, replace=True)

5. Verification Checklist

  • No Local Pandas: Ensure pandas (standard) is only used for metadata or small configurations, not for processing.
  • BigFrames ML: Ensure bigframes.ml is used for training.
  • Model Saved: Verify model.to_gbq is called to persist the model.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.