Instructions for generating scikit-learn pipelines without data leakage: Pipeline and ColumnTransformer, split-before-fit, cross-validation, task-appropriate metrics, safe persistence and documentation.
GEMINI.md. Downloaded files need to be placed in that repository path.## Gemini Machine Learning Pipelines
Applies to: **/*
When generating machine learning pipeline code with scikit-learn:
## Data preparation
- Split the data into train and test sets before any fitting (scalers, imputers, encoders, feature selection). For time-ordered data, split by time and use `TimeSeriesSplit`, never a random split.
- Put every preprocessing step inside a `Pipeline` so it is fitted only on training folds. Use `ColumnTransformer` to apply different steps to numeric and categorical columns.
```python
from sklearn.compose import ColumnTransformer
from sklearn.impute import SimpleImputer
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import cross_validate, train_test_split
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import OneHotEncoder, StandardScaler
numeric = ["age", "income"]
categorical = ["plan", "country"]
preprocess = ColumnTransformer([
("num", Pipeline([("impute", SimpleImputer(strategy="median")), ("scale", StandardScaler())]), numeric),
("cat", OneHotEncoder(handle_unknown="ignore"), categorical),
])
model = Pipeline([("prep", preprocess), ("clf", LogisticRegression(max_iter=1000))])
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, stratify=y, random_state=42
)
scores = cross_validate(model, X_train, y_train, cv=5, scoring=["roc_auc", "f1"])
```
## Feature engineering
- Implement custom features as transformers (`FunctionTransformer` or a class with `fit`/`transform`) inside the pipeline, so the same code runs at training and prediction time.
- Never use information from the target or from the future to build features.
## Training and evaluation
- Use cross-validation on the training set to compare models and tune hyperparameters (`GridSearchCV`/`RandomizedSearchCV` with the whole pipeline as the estimator). Evaluate on the held-out test set once, at the end.
- Choose metrics that match the task and class balance: ROC AUC, PR AUC, F1 and a confusion matrix for imbalanced classification; MAE/RMSE for regression. Always compare with a simple baseline (`DummyClassifier`/`DummyRegressor`).
- Set `random_state` where randomness is involved so results are reproducible.
## Persistence
- Save the whole fitted pipeline, not only the model. `joblib`/`pickle` files can execute code when loaded, so only load files from trusted sources; use `skops.io` when models are shared, and record the scikit-learn version used.
## Logging and monitoring
- Log parameters, metrics, data version and code version for each run (an experiment tracker such as MLflow, or structured logs).
- In production, monitor input feature distributions and prediction quality against the training baseline.
## Documentation
- Document the data source, target definition, features, split strategy, metrics with baseline, known limitations and intended use (a short model card).
Project context for Gemini Code Assist agent mode and Gemini CLI: how to respond, what finished code includes, and how to verify changes before proposing them.
System instructions for Gemini on React 19 + TypeScript: typed function components, accessible markup with useId, error boundaries, measured performance and review checklists.
Generate configuration handling code
Gemini
data-science
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
A churn model notebook scales the full dataset before train_test_split and reports 0.95 accuracy on a dataset where 92% of customers do not churn.
Write a scikit-learn pipeline for predicting churn from customers.csv (numeric: age, income; categorical: plan, country; target: churned).
Code that splits first (stratified), builds a ColumnTransformer + Pipeline, cross-validates with ROC AUC and F1 against a DummyClassifier baseline, evaluates once on the test set, saves the full pipeline with a note on pickle trust (or skops), and lists the documentation items for a model card.
Gemini CLI loads instructional context from GEMINI.md files: a global ~/.gemini/GEMINI.md, files in your workspace directories and their parents, and files discovered in subfolders as the agent works. The file name is configurable, so a project can tell Gemini CLI to read AGENTS.md instead of, or alongside, GEMINI.md. The rules in this directory are written as plain system instructions, so the same text can also be used as a system instruction in Gemini API or Google AI Studio requests.
GEMINI.mdStarting point, not a tested configuration for your repository. GEMINI.md has no file-scoping front matter; add this as a section, or place a GEMINI.md in the relevant subfolder. Review the instructions, adapt the file paths and run your project's existing checks.
## Gemini Machine Learning Pipelines
Applies to: **/*
When generating machine learning pipeline code with scikit-learn:
## Data preparation
- Split the data into train and test sets before any fitting (scalers, imputers, encoders, feature selection). For time-ordered data, split by time and use `TimeSeriesSplit`, never a random split.
- Put every preprocessing step inside a `Pipeline` so it is fitted only on training folds. Use `ColumnTransformer` to apply different steps to numeric and categorical columns.
```python
from sklearn.compose import ColumnTransformer
from sklearn.impute import SimpleImputer
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import cross_validate, train_test_split
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import OneHotEncoder, StandardScaler
numeric = ["age", "income"]
categorical = ["plan", "country"]
preprocess = ColumnTransformer([
("num", Pipeline([("impute", SimpleImputer(strategy="median")), ("scale", StandardScaler())]), numeric),
("cat", OneHotEncoder(handle_unknown="ignore"), categorical),
])
model = Pipeline([("prep", preprocess), ("clf", LogisticRegression(max_iter=1000))])
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, stratify=y, random_state=42
)
scores = cross_validate(model, X_train, y_train, cv=5, scoring=["roc_auc", "f1"])
```
## Feature engineering
- Implement custom features as transformers (`FunctionTransformer` or a class with `fit`/`transform`) inside the pipeline, so the same code runs at training and prediction time.
- Never use information from the target or from the future to build features.
## Training and evaluation
- Use cross-validation on the training set to compare models and tune hyperparameters (`GridSearchCV`/`RandomizedSearchCV` with the whole pipeline as the estimator). Evaluate on the held-out test set once, at the end.
- Choose metrics that match the task and class balance: ROC AUC, PR AUC, F1 and a confusion matrix for imbalanced classification; MAE/RMSE for regression. Always compare with a simple baseline (`DummyClassifier`/`DummyRegressor`).
- Set `random_state` where randomness is involved so results are reproducible.
## Persistence
- Save the whole fitted pipeline, not only the model. `joblib`/`pickle` files can execute code when loaded, so only load files from trusted sources; use `skops.io` when models are shared, and record the scikit-learn version used.
## Logging and monitoring
- Log parameters, metrics, data version and code version for each run (an experiment tracker such as MLflow, or structured logs).
- In production, monitor input feature distributions and prediction quality against the training baseline.
## Documentation
- Document the data source, target definition, features, split strategy, metrics with baseline, known limitations and intended use (a short model card).
Ask for a small change to one matching file. Check the tool's loaded context or instruction view, inspect the diff for the requested convention, and run the relevant build or test. A well-formatted file does not guarantee the model follows every instruction.
The Gemini CLI documentation states that Gemini CLI was replaced by Antigravity CLI on June 18, 2026 for unpaid-tier and Google One users. Check which CLI your account uses; Antigravity rules are covered on the Antigravity page. Gemini CLI does not need a separate AGENTS.md mechanism: its context file name is configurable through context.fileName in settings.json (the docs show ["AGENTS.md", "CONTEXT.md", "GEMINI.md"]). Without that setting it looks for GEMINI.md.
Documentation checked 2026-11-05: Gemini CLI docs: GEMINI.md context filesGemini CLI docs: System prompt override
Project context for Gemini Code Assist agent mode and Gemini CLI: how to respond, what finished code includes, and how to verify changes before proposing them.
System instructions for Gemini on React 19 + TypeScript: typed function components, accessible markup with useId, error boundaries, measured performance and review checklists.
Generate configuration handling code