Skip to Content
OchreML
How-To Guides

1-Line Scikit-Learn Migration

Migrate existing scikit-learn pipelines and estimators to OchreML with minimal import changes.

OchreML mirrors Scikit-Learn's module hierarchy, class names, hyperparameters, and fitted attributes (coef_, intercept_, classes_, n_features_in_, feature_importances_, etc.). In most scripts, migration is a single import swap. (*≧ω≦*)

Module-Level Swap

Replace sklearn with ochreml across your imports:

# Before (scikit-learn)
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestClassifier, HistGradientBoostingClassifier
from sklearn.model_selection import train_test_split, StratifiedKFold, GridSearchCV
from sklearn.pipeline import Pipeline
from sklearn.metrics import accuracy_score, f1_score, classification_report

# After (OchreML)
from ochreml.preprocessing import StandardScaler
from ochreml.linear_model import LogisticRegression
from ochreml.ensemble import RandomForestClassifier, HistGradientBoostingClassifier
from ochreml.model_selection import train_test_split, StratifiedKFold, GridSearchCV
from ochreml.pipeline import Pipeline
from ochreml.metrics import accuracy_score, f1_score, classification_report

You can also import any public estimator or utility directly from the top-level ochreml namespace (resolved lazily via PEP 562):

from ochreml import StandardScaler, Ridge, KMeans, PCA, Pipeline

Submodule Parity Map

Scikit-Learn SubmoduleOchreML SubmoduleCoverage Highlights
sklearn.linear_modelochreml.linear_model / ochreml.glmLinearRegression, Ridge, RidgeClassifier, RidgeCV, Lasso, ElasticNet, LogisticRegression, SGDClassifier, SGDRegressor, GLMs (Huber, Quantile, Poisson, Gamma, Tweedie)
sklearn.treeochreml.treeDecisionTreeClassifier, DecisionTreeRegressor
sklearn.ensembleochreml.ensembleRandomForest*, ExtraTrees*, GradientBoosting*, HistGradientBoosting*, AdaBoost*, IsolationForest, Bagging*, VotingClassifier, StackingClassifier
sklearn.svmochreml.svmLinearSVC, LinearSVR, SVC, SVR, OneClassSVM
sklearn.neighborsochreml.neighborsKNeighbors*, RadiusNeighbors*
sklearn.naive_bayesochreml.naive_bayesGaussianNB, MultinomialNB, BernoulliNB, ComplementNB
sklearn.clusterochreml.cluster / ochreml.cluster_advancedKMeans, MiniBatchKMeans, DBSCAN, OPTICS, SpectralClustering, AgglomerativeClustering, LocalOutlierFactor
sklearn.mixtureochreml.mixtureGaussianMixture
sklearn.decompositionochreml.decompositionPCA, TruncatedSVD, KernelPCA
sklearn.discriminant_analysisochreml.discriminant_analysisLinearDiscriminantAnalysis, QuadraticDiscriminantAnalysis
sklearn.cross_decompositionochreml.cross_decompositionNMF, CCA, PLSRegression
sklearn.manifoldochreml.manifoldTSNE, MDS
sklearn.kernel_ridgeochreml.kernel_ridgeKernelRidge
sklearn.neural_networkochreml.neural_networkMLPClassifier, MLPRegressor
sklearn.gaussian_processochreml.gaussian_processGaussianProcessRegressor, GaussianProcessClassifier
sklearn.preprocessingochreml.preprocessing19 scalers, encoders, discretizers, and nonlinear transformers
sklearn.imputeochreml.imputeSimpleImputer, MissingIndicator, KNNImputer, IterativeImputer
sklearn.feature_extractionochreml.feature_extractionDictVectorizer, FeatureHasher, CountVectorizer, TfidfTransformer, TfidfVectorizer, HashingVectorizer
sklearn.feature_selectionochreml.feature_selectionVarianceThreshold, SelectKBest, SelectPercentile, f_regression, f_classif, chi2, RFE, SelectFromModel
sklearn.kernel_approximationochreml.kernel_approximationRBFSampler
sklearn.composeochreml.composeColumnTransformer, TransformedTargetRegressor, make_column_transformer, make_column_selector
sklearn.pipelineochreml.pipelinePipeline, make_pipeline
sklearn.model_selectionochreml.model_selectiontrain_test_split, KFold, StratifiedKFold, GroupKFold, TimeSeriesSplit, GridSearchCV, RandomizedSearchCV, cross_val_score
sklearn.metricsochreml.metrics20 regression, classification, and clustering metrics
sklearn.multiclass / multioutputochreml.multiclass / ochreml.multioutputOneVsRestClassifier, MultiOutputRegressor

Setting a Global Default Device

Instead of passing device=... to every estimator after migrating, set the global default once at the top of your script:

import ochreml

# Options: "auto", "cpu", "cuda:0", "cuda:0,1", "cuda:all", "wgpu", "tpu:0"
ochreml.set_default_device("cuda:all")

All subsequently constructed estimators inherit the global default unless overridden per instance.

Replacing joblib.dump / pickle.dump

Switch model serialization to OchreML's native .dit format for compact, cross-device binary persistence:

# Before
# joblib.dump(model, "model.joblib")
# model = joblib.load("model.joblib")

# After
ochreml.save(model, "model.dit")
model = ochreml.load("model.dit", device="cpu")

OchreML enforces the .dit file extension on save() and load(). If a .dit file was written via joblib/pickle fallback (such as custom composite Python objects), ochreml.load() transparently falls back to deserializing it and applies .to(device) when requested.

Practical Migration Notes

  • Dense vs. Sparse inputs: OchreML currently operates on dense contiguous f64 arrays (native CSR/CSC sparse matrix support is scheduled for v1.0.0). Convert scipy.sparse matrices with .toarray() before passing them to estimators.
  • Zero-Copy Buffer Protocol: Passing C-contiguous np.float64 arrays avoids host memory copies across the Python-to-Rust boundary.
  • Numerical Parity: Across the 62 comparable Classical ML estimators in the v0.3.7a1 benchmark suite, OchreML matches scikit-learn's R2 and accuracy scores within floating-point tolerance (score_diff = 0.0 on deterministic linear, SVM, kernel, neighbor, naive Bayes, and discriminant models).

On this page