starlight-regression
v1.0.0
Published
Regression models for the Starlight ML ecosystem
Downloads
79
Maintainers
Readme
starlight-regression
A lightweight regression module for the Starlight Machine Learning ecosystem, providing simple and transparent linear regression with evaluation metrics.
Designed to be:
- Minimal
- Educational
- Dependency-free
- Pipeline-friendly
Installation
npm install starlight-regressionFeatures
- Linear Regression (Normal Equation)
- Automatic bias / intercept handling
- Batch predictions
- Built-in regression metrics
- No external dependencies
- Works seamlessly with other Starlight ML packages
Quick Start
import {
LinearRegression,
meanSquaredError,
rootMeanSquaredError,
r2Score
} from "starlight-regression";
const X = [
[1],
[2],
[3],
[4]
];
const y = [2, 4, 6, 8];
const model = new LinearRegression();
model.fit(X, y);
const predictions = model.predictBatch(X);
console.log("Predictions:", predictions);
console.log("MSE:", meanSquaredError(y, predictions));
console.log("RMSE:", rootMeanSquaredError(y, predictions));
console.log("R²:", r2Score(y, predictions));LinearRegression API
new LinearRegression(options?)
new LinearRegression({
fitIntercept: true // default
});| Option | Description |
| -------------- | ------------------------------ |
| fitIntercept | Automatically adds a bias term |
fit(X, y)
Train the regression model using the normal equation.
model.fit(X, y);X: 2D array of featuresy: 1D array of target values
predict(x)
Predict a single value.
model.predict([5]);predictBatch(X)
Predict multiple samples at once.
model.predictBatch(X);Regression Metrics
Mean Squared Error
meanSquaredError(yTrue, yPred);Root Mean Squared Error
rootMeanSquaredError(yTrue, yPred);R² Score
r2Score(yTrue, yPred);Measures how well the model explains the variance in the data.
Ecosystem Compatibility
starlight-regression integrates naturally with:
starlight-ml– tokenization & utilitiesstarlight-vec– feature vectorizationstarlight-pipeline– ML workflowsstarlight-eval– evaluation tools
Design Philosophy
- No hidden magic
- Pure JavaScript math
- Easy to read, modify, and learn from
- Ideal for education and lightweight ML tasks
Roadmap
- Polynomial regression
- Ridge / Lasso regression
- Gradient descent solver
- Pipeline integration helpers
License
MIT License
