mojolearn.host_model#

mojolearn.host_model(path)[source]#

Load a saved model for prediction on the CPU.

Chooses the CPU model from the file’s format: a HostForest for a random forest or extra-trees file, a HostGBDT for a GradientBoosting.save file, or the CPU model for a saved LinearRegression, Ridge, TruncatedSVD, LogisticRegression, PCA, NearestNeighbors, KNeighborsClassifier, KNeighborsRegressor, StandardScaler, MinMaxScaler, ElasticNet, Lasso, KernelRidge, Nystroem or RBFSampler. Any other format raises an error naming the format.

Parameters:

path (str or path-like) – The saved model file.

Returns:

model – An object with predict (and predict_proba for classifiers).

Examples

>>> import numpy as np, mojolearn
>>> X = np.random.default_rng(0).random((1000, 8), dtype=np.float32)
>>> mojolearn.RandomForestRegressor(n_estimators=20).fit(X, X[:, 0]).save("rf.npz")
>>> pred = mojolearn.host_model("rf.npz").predict(X)