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_reportYou 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, PipelineSubmodule Parity Map
| Scikit-Learn Submodule | OchreML Submodule | Coverage Highlights |
|---|---|---|
sklearn.linear_model | ochreml.linear_model / ochreml.glm | LinearRegression, Ridge, RidgeClassifier, RidgeCV, Lasso, ElasticNet, LogisticRegression, SGDClassifier, SGDRegressor, GLMs (Huber, Quantile, Poisson, Gamma, Tweedie) |
sklearn.tree | ochreml.tree | DecisionTreeClassifier, DecisionTreeRegressor |
sklearn.ensemble | ochreml.ensemble | RandomForest*, ExtraTrees*, GradientBoosting*, HistGradientBoosting*, AdaBoost*, IsolationForest, Bagging*, VotingClassifier, StackingClassifier |
sklearn.svm | ochreml.svm | LinearSVC, LinearSVR, SVC, SVR, OneClassSVM |
sklearn.neighbors | ochreml.neighbors | KNeighbors*, RadiusNeighbors* |
sklearn.naive_bayes | ochreml.naive_bayes | GaussianNB, MultinomialNB, BernoulliNB, ComplementNB |
sklearn.cluster | ochreml.cluster / ochreml.cluster_advanced | KMeans, MiniBatchKMeans, DBSCAN, OPTICS, SpectralClustering, AgglomerativeClustering, LocalOutlierFactor |
sklearn.mixture | ochreml.mixture | GaussianMixture |
sklearn.decomposition | ochreml.decomposition | PCA, TruncatedSVD, KernelPCA |
sklearn.discriminant_analysis | ochreml.discriminant_analysis | LinearDiscriminantAnalysis, QuadraticDiscriminantAnalysis |
sklearn.cross_decomposition | ochreml.cross_decomposition | NMF, CCA, PLSRegression |
sklearn.manifold | ochreml.manifold | TSNE, MDS |
sklearn.kernel_ridge | ochreml.kernel_ridge | KernelRidge |
sklearn.neural_network | ochreml.neural_network | MLPClassifier, MLPRegressor |
sklearn.gaussian_process | ochreml.gaussian_process | GaussianProcessRegressor, GaussianProcessClassifier |
sklearn.preprocessing | ochreml.preprocessing | 19 scalers, encoders, discretizers, and nonlinear transformers |
sklearn.impute | ochreml.impute | SimpleImputer, MissingIndicator, KNNImputer, IterativeImputer |
sklearn.feature_extraction | ochreml.feature_extraction | DictVectorizer, FeatureHasher, CountVectorizer, TfidfTransformer, TfidfVectorizer, HashingVectorizer |
sklearn.feature_selection | ochreml.feature_selection | VarianceThreshold, SelectKBest, SelectPercentile, f_regression, f_classif, chi2, RFE, SelectFromModel |
sklearn.kernel_approximation | ochreml.kernel_approximation | RBFSampler |
sklearn.compose | ochreml.compose | ColumnTransformer, TransformedTargetRegressor, make_column_transformer, make_column_selector |
sklearn.pipeline | ochreml.pipeline | Pipeline, make_pipeline |
sklearn.model_selection | ochreml.model_selection | train_test_split, KFold, StratifiedKFold, GroupKFold, TimeSeriesSplit, GridSearchCV, RandomizedSearchCV, cross_val_score |
sklearn.metrics | ochreml.metrics | 20 regression, classification, and clustering metrics |
sklearn.multiclass / multioutput | ochreml.multiclass / ochreml.multioutput | OneVsRestClassifier, 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
f64arrays (nativeCSR/CSCsparse matrix support is scheduled forv1.0.0). Convertscipy.sparsematrices with.toarray()before passing them to estimators. - Zero-Copy Buffer Protocol: Passing C-contiguous
np.float64arrays avoids host memory copies across the Python-to-Rust boundary. - Numerical Parity: Across the 62 comparable Classical ML estimators in the
v0.3.7a1benchmark suite, OchreML matches scikit-learn's R2 and accuracy scores within floating-point tolerance (score_diff = 0.0on deterministic linear, SVM, kernel, neighbor, naive Bayes, and discriminant models).