@kanaries/ml

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 Markdown

Use 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 APINotes
sklearn.linear_model.LinearRegressionLinear.LinearRegressionfit, predict, weights, and bias
sklearn.linear_model.LogisticRegressionLinear.LogisticRegressionGradient-based JS options differ from sklearn solver options
sklearn.linear_model.RidgeLinear.RidgeRegressionL2-regularized regression
sklearn.linear_model.RidgeClassifierLinear.RidgeClassifierLinear classification with L2 penalty
sklearn.linear_model.LassoLinear.LassoRegressionL1-regularized regression
sklearn.linear_model.ElasticNetLinear.ElasticNetCombined L1 and L2 regularization
sklearn.preprocessing.PolynomialFeatures + regressionLinear.PolynomialRegressionIntegrated polynomial regression helper
sklearn.tree.DecisionTreeClassifierTree.DecisionTreeClassifierGini/entropy, depth, and minimum split controls
sklearn.tree.DecisionTreeRegressorTree.DecisionTreeRegressorRegression tree
sklearn.tree.ExtraTreeClassifierTree.ExtraTreeClassifierRandomized thresholds
sklearn.tree.ExtraTreeRegressorTree.ExtraTreeRegressorRandomized regression tree
sklearn.ensemble.RandomForestClassifierEnsemble.RandomForestClassifierBootstrap aggregation and feature subsampling
sklearn.ensemble.RandomForestRegressorEnsemble.RandomForestRegressorForest regression
sklearn.ensemble.IsolationForestEnsemble.IsolationForestJS labels: 1 anomaly, 0 normal; sklearn uses -1 and 1
sklearn.ensemble.BaggingClassifierEnsemble.BaggingClassifierBootstrap ensemble
sklearn.ensemble.AdaBoostClassifierEnsemble.AdaBoostClassifierIncludes multiclass SAMME behavior
sklearn.ensemble.AdaBoostRegressorEnsemble.AdaBoostRegressorBoosted regression
sklearn.ensemble.GradientBoostingClassifierEnsemble.GradientBoostingClassifierStage-wise classification ensemble
sklearn.ensemble.GradientBoostingRegressorEnsemble.GradientBoostingRegressorStage-wise regression ensemble
xgboost.XGBClassifierEnsemble.XGBoostClassifierXGBoost-style estimator in the ensemble namespace
xgboost.XGBRegressorEnsemble.XGBoostRegressorXGBoost-style regression
sklearn.neighbors.KNeighborsClassifierNeighbors.KNearestNeighborsPositional k, weighting, and distance options
sklearn.neighbors.KNeighborsRegressorNeighbors.KNeighborsRegressorNeighbor regression
sklearn.neighbors.RadiusNeighborsClassifierNeighbors.RadiusNeighborsClassifierRadius-based classification
sklearn.neighbors.RadiusNeighborsRegressorNeighbors.RadiusNeighborsRegressorRadius-based regression
sklearn.neighbors.NearestCentroidNeighbors.NearestCentroidClass-centroid classifier
sklearn.neighbors.BallTreeNeighbors.BallTreeSpatial neighbor index
sklearn.neighbors.KDTreeNeighbors.KDTreeAxis-partitioned neighbor index
sklearn.cluster.KMeansClusters.KMeansfitPredict, centroids, inertia, seeds, and restarts
sklearn.cluster.kmeans_plusplusClusters.kmeansPlusPlusCenter initialization
sklearn.cluster.DBSCANClusters.DBScanNote JavaScript class capitalization
sklearn.cluster.OPTICSClusters.OPTICSDensity ordering
sklearn.cluster.MeanShiftClusters.MeanShiftMode-seeking clustering
hdbscan.HDBSCANClusters.HDBScanHDBSCAN-style density clustering
sklearn.decomposition.PCADecomposition.PCAfitTransform, components, variance, inverse transform
sklearn.decomposition.TruncatedSVDDecomposition.TruncatedSVDLow-rank decomposition without centering
sklearn.decomposition.SparsePCADecomposition.SparsePCASparse components
sklearn.manifold.TSNEManifold.TSNENonlinear visualization embedding
sklearn.manifold.MDSManifold.MDSDissimilarity-preserving embedding
sklearn.manifold.SpectralEmbeddingManifold.SpectralEmbeddingGraph spectral embedding
sklearn.manifold.LocallyLinearEmbeddingManifold.LocallyLinearEmbeddingLocal linear manifold embedding
sklearn.svm.SVCSVM.SVCLinear, RBF, polynomial, and sigmoid kernels
sklearn.svm.NuSVCSVM.NuSVCNu-parameterized classification
sklearn.svm.LinearSVCSVM.LinearSVCLinear support vector classification
sklearn.svm.LinearSVRSVM.LinearSVRLinear support vector regression
sklearn.naive_bayes.GaussianNBBayes.GaussianNBContinuous Gaussian features
sklearn.naive_bayes.MultinomialNBBayes.MultinomialNBNon-negative count features
sklearn.naive_bayes.ComplementNBBayes.ComplementNBImbalanced count classification
sklearn.naive_bayes.BernoulliNBBayes.BernoulliNBBinary features
sklearn.naive_bayes.CategoricalNBBayes.CategoricalNBEncoded categorical features
sklearn.semi_supervised.LabelPropagationSemiSupervised.LabelPropagationGraph-based propagation
sklearn.semi_supervised.LabelSpreadingSemiSupervised.LabelSpreadingRegularized label spreading
sklearn.neural_network.BernoulliRBMNeuralNetwork.BernoulliRBMBernoulli 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

  1. Match feature preparation and train/test splitting before comparing estimators.
  2. Check constructor names and defaults; JavaScript positional APIs are not always identical to Python keyword arguments.
  3. Fix random seeds where available, but expect random-number streams and tie breaking to differ.
  4. Compare predictions, scores, and tolerances on fixed data rather than serialized internal structures.
  5. 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.