Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: CI

on:
push:
branches: [main, "autoloop/**"]
pull_request:
branches: [main]

permissions:
contents: read

jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- name: Install dependencies
run: bun install

- name: Type check
run: bunx tsc --noEmit

- name: Run tests
run: bun test

lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- name: Install dependencies
run: bun install

- name: Lint
run: bunx biome check src tests

playground:
name: Build Playground
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- name: Install dependencies
run: bun install

- name: Build library bundle
run: bun build src/index.ts --outfile playground/tsikit-learn.js --target browser --minify

- name: Upload playground artifact
uses: actions/upload-artifact@v4
with:
name: playground
path: playground/

pages:
name: Deploy to GitHub Pages
runs-on: ubuntu-latest
needs: [test, playground]
if: github.ref == 'refs/heads/main'
permissions:
contents: read
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- uses: actions/checkout@v4

- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- name: Install dependencies
run: bun install

- name: Build library bundle
run: bun build src/index.ts --outfile playground/tsikit-learn.js --target browser --minify

- name: Setup Pages
uses: actions/configure-pages@v5

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: playground/

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
dist/
coverage/
79 changes: 79 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Agent Instructions for tsikit-learn

## Overview

`tsikit-learn` is a TypeScript port of [scikit-learn](https://scikit-learn.org/). The project is being built one feature at a time by the Autoloop agent.

## Stack

- **Runtime & bundler**: Bun
- **Language**: TypeScript (strictest settings — `strict: true`, `noUncheckedIndexedAccess: true`, `exactOptionalPropertyTypes: true`)
- **Linting**: Biome
- **Testing**: Bun test runner with fast-check for property-based tests
- **Data layer**: `tsb` (TypeScript pandas port) as a peer dependency; typed arrays for numeric computation

## Directory Structure

```
src/
index.ts — public entry point, re-exports everything
exceptions.ts — NotFittedError, ConvergenceWarning, etc.
base.ts — BaseEstimator, mixins, clone, check_is_fitted
utils/
extmath.ts — math utilities (safeDot, gramMatrix, cholesky, etc.)
validation.ts — input validation
multiclass.ts — multiclass helpers
class_weight.ts — class weight utilities
index.ts — re-exports all utils
preprocessing/
standard_scaler.ts — StandardScaler
minmax_scaler.ts — MinMaxScaler
label_encoder.ts — LabelEncoder
normalizer.ts — Normalizer
index.ts
metrics/
regression.ts — MSE, MAE, R², MAPE, explained_variance
classification.ts — accuracy, confusion_matrix, precision, recall, F1, log_loss
index.ts
model_selection/
split.ts — train_test_split, KFold, StratifiedKFold
index.ts
linear_model/
linear_regression.ts — LinearRegression (OLS via Cholesky)
ridge.ts — Ridge (L2 regularization)
index.ts
tests/
base.test.ts
preprocessing.test.ts
metrics_model_selection.test.ts
linear_model.test.ts
playground/
index.html — interactive demos, deployed to GitHub Pages
```

## TypeScript Conventions

- No `any`, no `@ts-ignore`, no `as` casts (unless provably safe)
- Use `Float64Array` for continuous numeric data, `Int32Array` for integer labels
- Use `?? 0` or null checks for `noUncheckedIndexedAccess` compliance
- Export everything from module `index.ts` files

## Evaluation Metric

The CI evaluation script counts TypeScript source files in `src/` (excluding `index.ts`) that contain `export`. Currently: **15 files**.

## Adding a New Module

1. Create `src/{module}/{feature}.ts` — implement the class with `fit`, `predict`/`transform`, `score`
2. Create or update `src/{module}/index.ts` — re-export from the new file
3. Update `src/index.ts` — add `export * from "./{module}/index.js"`
4. Add tests in `tests/{module}.test.ts`
5. Add a card to `playground/index.html`

## Running Locally

```bash
bun install
bun test
bunx tsc --noEmit
```
15 changes: 15 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"organizeImports": { "enabled": true },
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
},
"formatter": {
"enabled": true,
"indentStyle": "space",
"indentWidth": 2
}
}
2 changes: 2 additions & 0 deletions bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[test]
coverage = true
34 changes: 34 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "tsikit-learn",
"version": "0.1.0",
"description": "A complete TypeScript port of scikit-learn",
"type": "module",
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": "./dist/index.js",
"types": "./dist/index.d.ts"
}
},
"scripts": {
"build": "bun build src/index.ts --outdir dist --target browser",
"test": "bun test",
"typecheck": "bunx tsc --noEmit",
"lint": "bunx biome check src tests"
},
"devDependencies": {
"@biomejs/biome": "^1.9.4",
"fast-check": "^3.22.0",
"typescript": "^5.7.2"
},
"peerDependencies": {
"tsb": "^0.1.0"
},
"peerDependenciesMeta": {
"tsb": {
"optional": true
}
}
}
Loading
Loading