MLFlow¶
PyFunc をサポートする MLflow モデルを使用できます。MLFlow モデルに署名がある場合、 signature
引数はモデルから推測されます。署名がない場合は、 signature
か sample_input_data
のどちらかを提供する必要があります。
以下の追加オプションは、 options
ディクショナリで log_model
を呼び出すときに使用できます。
オプション |
説明 |
---|---|
|
MLFlow モデルのアーティファクトの URI。モデルのメタデータで |
|
|
|
|
例¶
import mlflow
from sklearn import datasets, model_selection, ensemble
db = datasets.load_diabetes(as_frame=True)
X_train, X_test, y_train, y_test = model_selection.train_test_split(db.data, db.target)
with mlflow.start_run() as run:
rf = ensemble.RandomForestRegressor(n_estimators=100, max_depth=6, max_features=3)
rf.fit(X_train, y_train)
# Use the model to make predictions on the test dataset.
predictions = rf.predict(X_test)
signature = mlflow.models.signature.infer_signature(X_test, predictions)
mlflow.sklearn.log_model(
rf,
"model",
signature=signature,
)
run_id = run.info.run_id
model_ref = registry.log_model(
mlflow.pyfunc.load_model(f"runs:/{run_id}/model"),
model_name="mlflowModel",
version_name="v1",
conda_dependencies=["mlflow<=2.4.0", "scikit-learn", "scipy"],
options={"ignore_mlflow_dependencies": True}
)
model_ref.run(X_test)