scikit-learn Equivalents
Translate scikit-learn estimators and workflows to JavaScript or TypeScript with a searchable sklearn-to-@kanaries/ml API mapping, runnable examples, and compatibility notes.
View as MarkdownUse this table when you know the scikit-learn class or function and need the closest @kanaries/ml equivalent for a browser or Node.js application. Both libraries use estimator-style fit, predict, transform, and fitPredict workflows where the algorithm permits it. Constructor syntax and label conventions can differ, so follow the linked JavaScript API before translating production code.
Quick translation example
Python (scikit-learn)
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier(
n_estimators=100,
max_depth=6,
random_state=42
)
model.fit(X, y)
predictions = model.predict(test_X)JavaScript / TypeScript (@kanaries/ml)
import { Ensemble } from '@kanaries/ml';
const model = new Ensemble.RandomForestClassifier({
nEstimators: 100,
max_depth: 6,
randomState: 42,
});
model.fit(X, y);
const predictions = model.predict(testX);Estimator and function equivalents
| scikit-learn Python API | @kanaries/ml JavaScript / TypeScript API | Notes |
|---|---|---|
sklearn.linear_model.LinearRegression | Linear.LinearRegression | fit, predict, weights, and bias |
sklearn.linear_model.LogisticRegression | Linear.LogisticRegression | Gradient-based JS options differ from sklearn solver options |
sklearn.linear_model.Ridge | Linear.RidgeRegression | L2-regularized regression |
sklearn.linear_model.RidgeClassifier | Linear.RidgeClassifier | Linear classification with L2 penalty |
sklearn.linear_model.Lasso | Linear.LassoRegression | L1-regularized regression |
sklearn.linear_model.ElasticNet | Linear.ElasticNet | Combined L1 and L2 regularization |
sklearn.preprocessing.PolynomialFeatures + regression | Linear.PolynomialRegression | Integrated polynomial regression helper |
sklearn.tree.DecisionTreeClassifier | Tree.DecisionTreeClassifier | Gini/entropy, depth, and minimum split controls |
sklearn.tree.DecisionTreeRegressor | Tree.DecisionTreeRegressor | Regression tree |
sklearn.tree.ExtraTreeClassifier | Tree.ExtraTreeClassifier | Randomized thresholds |
sklearn.tree.ExtraTreeRegressor | Tree.ExtraTreeRegressor | Randomized regression tree |
sklearn.ensemble.RandomForestClassifier | Ensemble.RandomForestClassifier | Bootstrap aggregation and feature subsampling |
sklearn.ensemble.RandomForestRegressor | Ensemble.RandomForestRegressor | Forest regression |
sklearn.ensemble.IsolationForest | Ensemble.IsolationForest | JS labels: 1 anomaly, 0 normal; sklearn uses -1 and 1 |
sklearn.ensemble.BaggingClassifier | Ensemble.BaggingClassifier | Bootstrap ensemble |
sklearn.ensemble.AdaBoostClassifier | Ensemble.AdaBoostClassifier | Includes multiclass SAMME behavior |
sklearn.ensemble.AdaBoostRegressor | Ensemble.AdaBoostRegressor | Boosted regression |
sklearn.ensemble.GradientBoostingClassifier | Ensemble.GradientBoostingClassifier | Stage-wise classification ensemble |
sklearn.ensemble.GradientBoostingRegressor | Ensemble.GradientBoostingRegressor | Stage-wise regression ensemble |
xgboost.XGBClassifier | Ensemble.XGBoostClassifier | XGBoost-style estimator in the ensemble namespace |
xgboost.XGBRegressor | Ensemble.XGBoostRegressor | XGBoost-style regression |
sklearn.neighbors.KNeighborsClassifier | Neighbors.KNearestNeighbors | Positional k, weighting, and distance options |
sklearn.neighbors.KNeighborsRegressor | Neighbors.KNeighborsRegressor | Neighbor regression |
sklearn.neighbors.RadiusNeighborsClassifier | Neighbors.RadiusNeighborsClassifier | Radius-based classification |
sklearn.neighbors.RadiusNeighborsRegressor | Neighbors.RadiusNeighborsRegressor | Radius-based regression |
sklearn.neighbors.NearestCentroid | Neighbors.NearestCentroid | Class-centroid classifier |
sklearn.neighbors.BallTree | Neighbors.BallTree | Spatial neighbor index |
sklearn.neighbors.KDTree | Neighbors.KDTree | Axis-partitioned neighbor index |
sklearn.cluster.KMeans | Clusters.KMeans | fitPredict, centroids, inertia, seeds, and restarts |
sklearn.cluster.kmeans_plusplus | Clusters.kmeansPlusPlus | Center initialization |
sklearn.cluster.DBSCAN | Clusters.DBScan | Note JavaScript class capitalization |
sklearn.cluster.OPTICS | Clusters.OPTICS | Density ordering |
sklearn.cluster.MeanShift | Clusters.MeanShift | Mode-seeking clustering |
hdbscan.HDBSCAN | Clusters.HDBScan | HDBSCAN-style density clustering |
sklearn.decomposition.PCA | Decomposition.PCA | fitTransform, components, variance, inverse transform |
sklearn.decomposition.TruncatedSVD | Decomposition.TruncatedSVD | Low-rank decomposition without centering |
sklearn.decomposition.SparsePCA | Decomposition.SparsePCA | Sparse components |
sklearn.manifold.TSNE | Manifold.TSNE | Nonlinear visualization embedding |
sklearn.manifold.MDS | Manifold.MDS | Dissimilarity-preserving embedding |
sklearn.manifold.SpectralEmbedding | Manifold.SpectralEmbedding | Graph spectral embedding |
sklearn.manifold.LocallyLinearEmbedding | Manifold.LocallyLinearEmbedding | Local linear manifold embedding |
sklearn.svm.SVC | SVM.SVC | Linear, RBF, polynomial, and sigmoid kernels |
sklearn.svm.NuSVC | SVM.NuSVC | Nu-parameterized classification |
sklearn.svm.LinearSVC | SVM.LinearSVC | Linear support vector classification |
sklearn.svm.LinearSVR | SVM.LinearSVR | Linear support vector regression |
sklearn.naive_bayes.GaussianNB | Bayes.GaussianNB | Continuous Gaussian features |
sklearn.naive_bayes.MultinomialNB | Bayes.MultinomialNB | Non-negative count features |
sklearn.naive_bayes.ComplementNB | Bayes.ComplementNB | Imbalanced count classification |
sklearn.naive_bayes.BernoulliNB | Bayes.BernoulliNB | Binary features |
sklearn.naive_bayes.CategoricalNB | Bayes.CategoricalNB | Encoded categorical features |
sklearn.semi_supervised.LabelPropagation | SemiSupervised.LabelPropagation | Graph-based propagation |
sklearn.semi_supervised.LabelSpreading | SemiSupervised.LabelSpreading | Regularized label spreading |
sklearn.neural_network.BernoulliRBM | NeuralNetwork.BernoulliRBM | Bernoulli restricted Boltzmann machine |
Metrics and preprocessing equivalents
Metrics includes accuracyScore, precisionScore, recallScore, f1Score, confusionMatrix, rocCurve, rocAucScore, precisionRecallCurve, meanSquaredError, r2Score, and adjustedRandScore. utils.Preprocessing provides StandardScaler, MinMaxScaler, and MaxAbsScaler. utils.ModelSelection includes K-fold splitters, grid search, randomized search, and cross-validation. See the Metrics API and Utilities API.
Translation checklist
- Match feature preparation and train/test splitting before comparing estimators.
- Check constructor names and defaults; JavaScript positional APIs are not always identical to Python keyword arguments.
- Fix random seeds where available, but expect random-number streams and tie breaking to differ.
- Compare predictions, scores, and tolerances on fixed data rather than serialized internal structures.
- Confirm label conventions, especially Isolation Forest and any metric's positive class.
For interactive examples, open the algorithm playgrounds. For package-wide installation and runtime guidance, return to the documentation home.
Build JavaScript Machine Learning
Discover how to train and deploy machine learning models in JavaScript and TypeScript using @kanaries/ml, including installation, core features, tutorials, and API references.
Isolation Forest in JavaScript — Anomaly Detection Guide and Interactive Demo
Learn how Isolation Forest detects anomalies, tune contamination and tree count in an interactive browser demo, and implement outlier scoring with @kanaries/ml in JavaScript or TypeScript.