LogisticRegression
API and practical guide for LogisticRegression in @kanaries/ml, including when to use it in JavaScript and TypeScript ML workflows.
Linear.LogisticRegression
interface LogisticRegressionProps {
learningRate?: number;
maxIter?: number;
}
constructor(props: LogisticRegressionProps = {})Performs binary logistic regression optimized with gradient descent. The
learningRate controls the step size during optimization and maxIter
specifies the number of iterations.
Methods
fit(trainX: number[][], trainY: number[]): voidpredict(testX: number[][]): number[]
fit
trainX- Training features with shape[nSamples, nFeatures].trainY- Binary labels for each training sample.
predict
testX- Feature matrix to classify.
Example
const clf = new LogisticRegression();
clf.fit(trainX, trainY);
const result = clf.predict(testX);Practical guide: LogisticRegression in JavaScript and TypeScript
LogisticRegression estimates class probabilities for binary classification with stable, interpretable coefficients.
When to use LogisticRegression
- You need calibrated probability scores for threshold-based decisions.
- Binary outcomes are influenced by approximately linear decision boundaries.
- You want a strong and explainable baseline in TypeScript projects.
Implementation workflow
- Standardize inputs and confirm label quality for binary classes.
- Fit with appropriate iteration settings and monitor convergence.
- Tune decision threshold based on business costs of false positives/negatives.
JavaScript deployment notes
- Prefer feature scaling for distance-based and gradient-based algorithms to improve stability.
- In browser apps, run heavy training in Web Workers to keep UI interactions smooth.
- Keep a simple baseline from the same module as a fallback model for comparison.
Search intents this page targets
LogisticRegression JavaScriptLogisticRegression TypeScriptLogisticRegression browser machine learning@kanaries/ml LogisticRegression
FAQ
What problem does LogisticRegression solve in JavaScript machine learning projects?
LogisticRegression helps teams implement production-ready ML workflows in browser and Node.js environments with a familiar scikit-learn-style API.
When should I choose LogisticRegression instead of other Linear algorithms?
Use LogisticRegression when it best matches your data shape, labeling strategy, and runtime constraints. Benchmark against at least one alternative in the same module before finalizing defaults.
Can I run LogisticRegression in both browser and Node.js with @kanaries/ml?
Yes. @kanaries/ml is designed for JavaScript and TypeScript runtimes across browser applications, server-side Node.js services, and edge-friendly workflows.