Skip to content

Instantly share code, notes, and snippets.

View betatim's full-sized avatar
🤠
Not my first rodeo

Tim Head betatim

🤠
Not my first rodeo
View GitHub Profile
@betatim
betatim / bench_pipeline_size_sweep.py
Created September 2, 2026 07:18
Benchmark for `fit` and `predct` at different `n_samples` for https://github.com/scikit-learn/scikit-learn/issues/34604
"""Sweep pipeline `fit` and `predict` runtime against the size of X.
This script times
StandardScaler -> Nystroem -> LogisticRegression
as a function of how much data it is given, in two independent sweeps:
fit GridSearchCV(pipeline, PARAM_GRID, cv=3).fit(X[:n], y[:n]),
for n from 2_000 to 100_000
@betatim
betatim / cuda-linux-1.txt
Created September 1, 2026 11:22
Always store attributes as numpy in scikit-learn GPU
numpy
as-is as numpy difference added
search 1.18s 1.18s -0.0% -164us
predict 24.2ms 19.1ms -20.9% -5.1ms
serve/call 897us 930us +3.7% 33us
score 10.4ms 10.9ms +4.8% 493us
one 10-row predict, step by step:
scale.transform 111us 135us +22.2% 24us
kernel.transform 572us 588us +2.8% 16us
clf.predict 206us 202us -2.2% -5us
@betatim
betatim / bench_store_fitted_as_numpy.py
Created August 10, 2026 14:59
Use this with https://github.com/scikit-learn/scikit-learn/pull/34667 (tested with `16de9236116f0dd3dcc769eaea781d389a6ae419`)
"""Benchmark storing fitted attributes as NumPy.
Times a PCA + LogisticRegression pipeline with and without the
`store_fitted_as_numpy` configuration option added in
https://github.com/scikit-learn/scikit-learn/pull/34667, for
https://github.com/scikit-learn/scikit-learn/issues/34604.
Needs that branch checked out. Run it with no arguments:
python bench_store_fitted_as_numpy.py
@betatim
betatim / SKILL.md
Created June 11, 2026 14:00
Produce a structured walkthrough of a GitHub PR ordered by causal dependency.
name pr-walkthrough
description Produce a structured walkthrough of a GitHub PR ordered by causal dependency. Use when the user asks to walk through, analyze, or understand a PR's changes.

PR Walkthrough

Generate a causal-dependency-ordered walkthrough of a GitHub PR and write it to agents/reviews/ in the repository.

This skill is scoped to PRs in the current repository. Cross-repo PRs are out of scope.

@betatim
betatim / salary_pipeline.py
Created June 2, 2026 12:40
Code from the skrub gallery
import numpy as np
from sklearn.ensemble import RandomForestRegressor
from sklearn.model_selection import cross_validate
from skrub import tabular_pipeline
from skrub.datasets import fetch_employee_salaries
def main():
print("Loading employee salaries dataset ...")
data = fetch_employee_salaries()
#!/usr/bin/env python3
"""
Employee Salary Prediction
==========================
Predict current annual salary for Montgomery County employees
using a scikit-learn pipeline with mixed feature types.
"""
try:
import cuml.accel
@betatim
betatim / AGENTS.md
Created April 30, 2026 07:36
My cuml `AGENTS.md`

AGENTS Instruction

This file contains is additional guidance for AI agents and other AI editors.


Core Principles

These principles reduce common LLM coding mistakes. Apply them to every task.

@betatim
betatim / gridsearch.py
Created April 13, 2026 15:00
GridSearchCV on a (random) pipeline. Main take away is that fitting the pipeline takes seconds.
"""
Pipeline(StandardScaler, PCA, RandomForest) with GridSearchCV
=============================================================
GridSearchCV over an all-proxy Pipeline on the full Forest Cover Type
dataset (581K samples, 54 features, 7 classes).
Pipeline: StandardScaler -> PCA -> RandomForestClassifier
All three steps are cuml.accel proxies, so the GridSearchCV patch
@betatim
betatim / bench.py
Created April 13, 2026 14:45
Estimate how long it takes to "transfer" a Numpy array to a Cupy array
"""
Benchmark: numpy-to-cupy (CPU-to-GPU) transfer times on this machine.
Target: GPU 1 (NVIDIA RTX A6000, 48 GB, PCIe Gen4 x16 slot)
"""
import time
import statistics
import numpy as np
import cupy as cp
@betatim
betatim / analysis.py
Created March 24, 2026 14:51
A generated workflow that does "single cell" analysis. The main point of this is to provide something a model can accelerate
import tarfile
import time
import urllib.request
from collections import OrderedDict
from pathlib import Path
import numpy as np
import scipy.io
import scipy.sparse
from sklearn.decomposition import TruncatedSVD