from pycaret.datasets import get_data
data = get_data('insurance', verbose=False)
data.drop('charges', axis=1, inplace=True)
data.head()
age | sex | bmi | children | smoker | region | |
---|---|---|---|---|---|---|
0 | 19 | female | 27.900 | 0 | yes | southwest |
1 | 18 | male | 33.770 | 1 | no | southeast |
2 | 28 | male | 33.000 | 3 | no | southeast |
3 | 33 | male | 22.705 | 0 | no | northwest |
4 | 32 | male | 28.880 | 0 | no | northwest |
import mlflow
def score_model(data, model_name, model_version):
mlflow.set_tracking_uri("sqlite:///mlruns.db")
model_uri = "models:/{}/{}".format(model_name, model_version)
model = mlflow.pyfunc.load_model(model_uri)
return model.predict(data)
score_model(data, 'my_first_model', 1)
array([18894.26007319, 3698.2875344 , 6029.27157845, ..., 2442.28835297, 2613.21866387, 28782.04091164])
score_model(data, 'my_first_model', 2)
array([16831.03017578, 2908.97255127, 4915.3686792 , ..., 2035.52375305, 2061.27198486, 28688.36953125])
score_model(data, 'my_first_model', 3)
array([25119.76880225, 4104.82323122, 6043.30438595, ..., 4195.51717011, 1111.38184836, 36858.02738907])
from pycaret.regression import load_model, predict_model
l = load_model('mlruns/1/c391ad05516442eb85c5defd46c27931/artifacts/model/model')
Transformation Pipeline and Model Successfully Loaded
print(l)
Pipeline(steps=[('dtypes', DataTypes_Auto_infer(display_types=False, ml_usecase='regression', target='charges')), ('imputer', Simple_Imputer(categorical_strategy='not_available', fill_value_categorical=None, fill_value_numerical=None, numeric_strategy='mean', target_variable=None)), ('new_levels1', New_Catagorical_Levels_in_TestData(replacement_strategy='leas... ('binn', 'passthrough'), ('rem_outliers', 'passthrough'), ('cluster_all', 'passthrough'), ('dummy', Dummify(target='charges')), ('fix_perfect', Remove_100(target='charges')), ('clean_names', Clean_Colum_Names()), ('feature_select', 'passthrough'), ('fix_multi', 'passthrough'), ('dfs', 'passthrough'), ('pca', 'passthrough'), ['trained_model', GradientBoostingRegressor(random_state=123)]])
predictions = predict_model(l, data=data)
predictions.head()
age | sex | bmi | children | smoker | region | Label | |
---|---|---|---|---|---|---|---|
0 | 19 | female | 27.900 | 0 | yes | southwest | 18894.260073 |
1 | 18 | male | 33.770 | 1 | no | southeast | 3698.287534 |
2 | 28 | male | 33.000 | 3 | no | southeast | 6029.271578 |
3 | 33 | male | 22.705 | 0 | no | northwest | 8958.189116 |
4 | 32 | male | 28.880 | 0 | no | northwest | 3900.039002 |