Model¶
Each sub-module of nextmv_sklearn
has a convenience function for creating
native sklearn
model objects from nextmv.Options
. This convenience function
allows you to set up a model using the parameters that are customized through
options. Notice that the return type is an sklearn.<Model>
.
Consider the following examples, which make use of the classic diabetes dataset to fit a model and then make a prediction.
Dummy¶
Reference
Find the reference for the dummy.model
module here.
import time
from nextmv_sklearn import dummy
from sklearn.datasets import load_diabetes
X, y = load_diabetes(return_X_y=True)
start_time = time.time()
options = dummy.DummyRegressorOptions().to_nextmv()
model = dummy.DummyRegressor(options)
fit = model.fit(X, y)
print(fit.predict(X[:1]))
Run the script:
Ensemble¶
Reference
Find the reference for the ensemble.model
module here.
-
GradientBoostingRegressor
import time from nextmv_sklearn import ensemble from sklearn.datasets import load_diabetes X, y = load_diabetes(return_X_y=True) start_time = time.time() options = ensemble.GradientBoostingRegressorOptions().to_nextmv() model = ensemble.GradientBoostingRegressor(options) fit = model.fit(X, y) print(fit.predict(X[:1]))
Run the script:
-
RandomForestRegressor
import time from nextmv_sklearn import ensemble from sklearn.datasets import load_diabetes X, y = load_diabetes(return_X_y=True) start_time = time.time() options = ensemble.RandomForestRegressorOptions().to_nextmv() model = ensemble.RandomForestRegressor(options) fit = model.fit(X, y) print(fit.predict(X[:1]))
Run the script:
Linear model¶
Reference
Find the reference for the linear_model.model
module here.
import time
from nextmv_sklearn import linear_model
from sklearn.datasets import load_diabetes
X, y = load_diabetes(return_X_y=True)
start_time = time.time()
options = linear_model.LinearRegressionOptions().to_nextmv()
model = linear_model.LinearRegression(options)
fit = model.fit(X, y)
print(fit.predict(X[:1]))
Run the script:
Neural network¶
Reference
Find the reference for the neural_network.model
module here.
import time
from nextmv_sklearn import neural_network
from sklearn.datasets import load_diabetes
X, y = load_diabetes(return_X_y=True)
start_time = time.time()
options = neural_network.MLPRegressorOptions().to_nextmv()
model = neural_network.MLPRegressor(options)
fit = model.fit(X, y)
print(fit.predict(X[:1]))
Run the script:
Tree¶
Reference
Find the reference for the tree.model
module here.
import time
from nextmv_sklearn import tree
from sklearn.datasets import load_diabetes
X, y = load_diabetes(return_X_y=True)
start_time = time.time()
options = tree.DecisionTreeRegressorOptions().to_nextmv()
model = tree.DecisionTreeRegressor(options)
fit = model.fit(X, y)
print(fit.predict(X[:1]))
Run the script: