Mlflow was activated as per following:
import mlflow
mlflow.set_tracking_uri("sqlite:///mlflow.db")
mlflow.set_experiment("project-2")
mlflow.autolog()
Output message after activation was fine as per following:
2022/09/24 18:00:58 INFO mlflow.tracking.fluent: Autologging successfully enabled for statsmodels.
2022/09/24 18:00:58 INFO mlflow.tracking.fluent: Autologging successfully enabled for sklearn.
2022/09/24 18:00:58 INFO mlflow.tracking.fluent: Autologging successfully enabled for lightgbm.
However, when i tried to run the following regression model.
lr_baseline = LinearRegression()
lr_baseline.fit(X_train, y_train)
y_pred = lr_baseline.predict(X_test)
with mlflow.start_run():
baseline_train_r2 = lr_baseline.score(X_train, y_train)
baseline_test_r2 = lr_baseline.score(X_test, y_test)
baseline_cv_r2 = cross_val_score(lr_baseline, X_train, y_train).mean()
print(f"""Baseline R2 score for train data: {baseline_train_r2}
Baseline R2 score for test data: {baseline_test_r2},
Baseline cross validated R2 score for train data: {baseline_cv_r2}""")
MLflow shows the following warning.
2022/09/24 18:24:04 INFO mlflow.utils.autologging_utils: Created MLflow autologging run with ID 'a843adb4410d46ff855b725479b0bcf0', which will track hyperparameters, performance metrics, model artifacts, and lineage information for the current sklearn workflow
2022/09/24 18:24:09 WARNING mlflow.models.model: Logging model metadata to the tracking server has failed, possibly due older server version. The model artifacts have been logged successfully under ./mlruns/1/a843adb4410d46ff855b725479b0bcf0/artifacts. In addition to exporting model artifacts, MLflow clients 1.7.0 and above attempt to record model metadata to the tracking store. If logging to a mlflow server via REST, consider upgrading the server version to MLflow 1.7.0 or above.
2022/09/24 18:24:14 WARNING mlflow.models.model: Logging model metadata to the tracking server has failed, possibly due older server version. The model artifacts have been logged successfully under ./mlruns/1/ed3439cbaed04b87bd4ab8764eaad894/artifacts. In addition to exporting model artifacts, MLflow clients 1.7.0 and above attempt to record model metadata to the tracking store. If logging to a mlflow server via REST, consider upgrading the server version to MLflow 1.7.0 or above.
2022/09/24 18:24:18 WARNING mlflow.models.model: Logging model metadata to the tracking server has failed, possibly due older server version. The model artifacts have been logged successfully under ./mlruns/1/ed3439cbaed04b87bd4ab8764eaad894/artifacts. In addition to exporting model artifacts, MLflow clients 1.7.0 and above attempt to record model metadata to the tracking store. If logging to a mlflow server via REST, consider upgrading the server version to MLflow 1.7.0 or above.
2022/09/24 18:24:22 WARNING mlflow.models.model: Logging model metadata to the tracking server has failed, possibly due older server version. The model artifacts have been logged successfully under ./mlruns/1/ed3439cbaed04b87bd4ab8764eaad894/artifacts. In addition to exporting model artifacts, MLflow clients 1.7.0 and above attempt to record model metadata to the tracking store. If logging to a mlflow server via REST, consider upgrading the server version to MLflow 1.7.0 or above.
2022/09/24 18:24:26 WARNING mlflow.models.model: Logging model metadata to the tracking server has failed, possibly due older server version. The model artifacts have been logged successfully under ./mlruns/1/ed3439cbaed04b87bd4ab8764eaad894/artifacts. In addition to exporting model artifacts, MLflow clients 1.7.0 and above attempt to record model metadata to the tracking store. If logging to a mlflow server via REST, consider upgrading the server version to MLflow 1.7.0 or above.
2022/09/24 18:24:30 WARNING mlflow.models.model: Logging model metadata to the tracking server has failed, possibly due older server version. The model artifacts have been logged successfully under ./mlruns/1/ed3439cbaed04b87bd4ab8764eaad894/artifacts. In addition to exporting model artifacts, MLflow clients 1.7.0 and above attempt to record model metadata to the tracking store. If logging to a mlflow server via REST, consider upgrading the server version to MLflow 1.7.0 or above.
Although i am still able to download from mlflow, i am unable to run the downloaded model.
from mlflow.artifacts import download_artifacts
import mlflow.pyfunc
full_path = './mlruns/1/ed3439cbaed04b87bd4ab8764eaad894/artifacts/model'
download_artifacts(full_path, dst_path='.')
model = mlflow.pyfunc.load_model(model_uri="./model") # saved trained model is within the best_estimator folder
model.predict(df_submit_cleaned)
Output error message when i tried to run the downloaded model is as follows:
---------------------------------------------------------------------------
MlflowException Traceback (most recent call last)
Cell In [58], line 1
----> 1 model.predict(df_submit_cleaned)
File ~\anaconda3\envs\dsi-sg\lib\site-packages\mlflow\pyfunc\__init__.py:372, in PyFuncModel.predict(self, data)
370 input_schema = self.metadata.get_input_schema()
371 if input_schema is not None:
--> 372 data = _enforce_schema(data, input_schema)
373 return self._predict_fn(data)
File ~\anaconda3\envs\dsi-sg\lib\site-packages\mlflow\models\utils.py:545, in _enforce_schema(pfInput, input_schema)
543 if extra_cols:
544 message += " Note that there were extra inputs: {0}".format(extra_cols)
--> 545 raise MlflowException(message)
546 elif not input_schema.is_tensor_spec():
547 # The model signature does not specify column names => we can only verify column count.
548 num_actual_columns = len(pfInput.columns)
MlflowException: Model is missing inputs ['MS SubClass_120', 'MS SubClass_150', 'MS SubClass_160', 'MS SubClass_180', 'MS SubClass_190', 'MS SubClass_20', 'MS SubClass_30', 'MS SubClass_40', 'MS SubClass_45', 'MS SubClass_50', 'MS SubClass_60', 'MS SubClass_70', 'MS SubClass_75', 'MS SubClass_80', 'MS SubClass_85', 'MS SubClass_90', 'MS Zoning_A (agr)', 'MS Zoning_C (all)', 'MS Zoning_FV', 'MS Zoning_I (all)', 'MS Zoning_RH', 'MS Zoning_RL', 'MS Zoning_RM', 'Street_Grvl', 'Street_Pave', 'Alley_0', 'Alley_Grvl', 'Alley_Pave', 'Lot Shape_IR1', 'Lot Shape_IR2', 'Lot Shape_IR3', 'Lot Shape_Reg', 'Land Contour_Bnk', 'Land Contour_HLS', 'Land Contour_Low', 'Land Contour_Lvl', 'Utilities_AllPub', 'Utilities_NoSeWa', 'Utilities_NoSewr', 'Lot Config_Corner', 'Lot Config_CulDSac', 'Lot Config_FR2', 'Lot Config_FR3', 'Lot Config_Inside', 'Land Slope_Gtl', 'Land Slope_Mod', 'Land Slope_Sev', 'Neighborhood_Blmngtn', 'Neighborhood_Blueste', 'Neighborhood_BrDale', 'Neighborhood_BrkSide', 'Neighborhood_ClearCr', 'Neighborhood_CollgCr', 'Neighborhood_Crawfor', 'Neighborhood_Edwards', 'Neighborhood_Gilbert', 'Neighborhood_Greens', 'Neighborhood_GrnHill', 'Neighborhood_IDOTRR', 'Neighborhood_Landmrk', 'Neighborhood_MeadowV', 'Neighborhood_Mitchel', 'Neighborhood_NAmes', 'Neighborhood_NPkVill', 'Neighborhood_NWAmes', 'Neighborhood_NoRidge', 'Neighborhood_NridgHt', 'Neighborhood_OldTown', 'Neighborhood_SWISU', 'Neighborhood_Sawyer', 'Neighborhood_SawyerW', 'Neighborhood_Somerst', 'Neighborhood_StoneBr', 'Neighborhood_Timber', 'Neighborhood_Veenker', 'Condition 1_Artery', 'Condition 1_Feedr', 'Condition 1_Norm', 'Condition 1_PosA', 'Condition 1_PosN', 'Condition 1_RRAe', 'Condition 1_RRAn', 'Condition 1_RRNe', 'Condition 1_RRNn', 'Condition 2_Artery', 'Condition 2_Feedr', 'Condition 2_Norm', 'Condition 2_PosA', 'Condition 2_PosN', 'Condition 2_RRAe', 'Condition 2_RRAn', 'Condition 2_RRNn', 'Bldg Type_1Fam', 'Bldg Type_2fmCon', 'Bldg Type_Duplex', 'Bldg Type_Twnhs', 'Bldg Type_TwnhsE', 'House Style_1.5Fin', 'House Style_1.5Unf', 'House Style_1Story', 'House Style_2.5Fin', 'House Style_2.5Unf', 'House Style_2Story', 'House Style_SFoyer', 'House Style_SLvl', 'Roof Style_Flat', 'Roof Style_Gable', 'Roof Style_Gambrel', 'Roof Style_Hip', 'Roof Style_Mansard', 'Roof Style_Shed', 'Roof Matl_ClyTile', 'Roof Matl_CompShg', 'Roof Matl_Membran', 'Roof Matl_Tar&Grv', 'Roof Matl_WdShake', 'Roof Matl_WdShngl', 'Exterior 1st_AsbShng', 'Exterior 1st_AsphShn', 'Exterior 1st_BrkComm', 'Exterior 1st_BrkFace', 'Exterior 1st_CBlock', 'Exterior 1st_CemntBd', 'Exterior 1st_HdBoard', 'Exterior 1st_ImStucc', 'Exterior 1st_MetalSd', 'Exterior 1st_Plywood', 'Exterior 1st_Stone', 'Exterior 1st_Stucco', 'Exterior 1st_VinylSd', 'Exterior 1st_Wd Sdng', 'Exterior 1st_WdShing', 'Mas Vnr Type_0', 'Mas Vnr Type_BrkCmn', 'Mas Vnr Type_BrkFace', 'Mas Vnr Type_None', 'Mas Vnr Type_Stone', 'Exter Qual_Ex', 'Exter Qual_Fa', 'Exter Qual_Gd', 'Exter Qual_TA', 'Exter Cond_Ex', 'Exter Cond_Fa', 'Exter Cond_Gd', 'Exter Cond_Po', 'Exter Cond_TA', 'Foundation_BrkTil', 'Foundation_CBlock', 'Foundation_PConc', 'Foundation_Slab', 'Foundation_Stone', 'Foundation_Wood', 'Bsmt Qual_0', 'Bsmt Qual_Ex', 'Bsmt Qual_Fa', 'Bsmt Qual_Gd', 'Bsmt Qual_Po', 'Bsmt Qual_TA', 'Bsmt Cond_0', 'Bsmt Cond_Ex', 'Bsmt Cond_Fa', 'Bsmt Cond_Gd', 'Bsmt Cond_Po', 'Bsmt Cond_TA', 'Bsmt Exposure_0', 'Bsmt Exposure_Av', 'Bsmt Exposure_Gd', 'Bsmt Exposure_Mn', 'Bsmt Exposure_No', 'BsmtFin Type 1_0', 'BsmtFin Type 1_ALQ', 'BsmtFin Type 1_BLQ', 'BsmtFin Type 1_GLQ', 'BsmtFin Type 1_LwQ', 'BsmtFin Type 1_Rec', 'BsmtFin Type 1_Unf', 'BsmtFin Type 2_0', 'BsmtFin Type 2_ALQ', 'BsmtFin Type 2_BLQ', 'BsmtFin Type 2_GLQ', 'BsmtFin Type 2_LwQ', 'BsmtFin Type 2_Rec', 'BsmtFin Type 2_Unf', 'Heating_GasA', 'Heating_GasW', 'Heating_Grav', 'Heating_OthW', 'Heating_Wall', 'Heating QC_Ex', 'Heating QC_Fa', 'Heating QC_Gd', 'Heating QC_Po', 'Heating QC_TA', 'Central Air_N', 'Central Air_Y', 'Electrical_FuseA', 'Electrical_FuseF', 'Electrical_FuseP', 'Electrical_Mix', 'Electrical_SBrkr', 'Kitchen Qual_Ex', 'Kitchen Qual_Fa', 'Kitchen Qual_Gd', 'Kitchen Qual_TA', 'Functional_Maj1', 'Functional_Maj2', 'Functional_Min1', 'Functional_Min2', 'Functional_Mod', 'Functional_Sal', 'Functional_Sev', 'Functional_Typ', 'Garage Type_0', 'Garage Type_2Types', 'Garage Type_Attchd', 'Garage Type_Basment', 'Garage Type_BuiltIn', 'Garage Type_CarPort', 'Garage Type_Detchd', 'Garage Finish_0', 'Garage Finish_Fin', 'Garage Finish_RFn', 'Garage Finish_Unf', 'Garage Cond_0', 'Garage Cond_Ex', 'Garage Cond_Fa', 'Garage Cond_Gd', 'Garage Cond_Po', 'Garage Cond_TA', 'Paved Drive_N', 'Paved Drive_P', 'Paved Drive_Y', 'Fence_0', 'Fence_GdPrv', 'Fence_GdWo', 'Fence_MnPrv', 'Fence_MnWw', 'Misc Feature_0', 'Misc Feature_Elev', 'Misc Feature_Gar2', 'Misc Feature_Othr', 'Misc Feature_Shed', 'Misc Feature_TenC', 'Sale Type_COD', 'Sale Type_CWD', 'Sale Type_Con', 'Sale Type_ConLD', 'Sale Type_ConLI', 'Sale Type_ConLw', 'Sale Type_New', 'Sale Type_Oth', 'Sale Type_WD ']. Note that there were extra inputs: ['Exter Qual', 'Lot Shape', 'Bsmt Qual', 'Foundation', 'Functional', 'Neighborhood', 'Fence', 'Sale Type', 'Condition 2', 'BsmtFin Type 2', 'Lot Config', 'Garage Finish', 'BsmtFin Type 1', 'Garage Cond', 'MS SubClass', 'Exterior 1st', 'Roof Style', 'Street', 'Heating', 'Central Air', 'Garage Type', 'Paved Drive', 'Land Contour', 'Roof Matl', 'Alley', 'Bsmt Cond', 'Mas Vnr Type', 'Kitchen Qual', 'House Style', 'Bldg Type', 'MS Zoning', 'Misc Feature', 'Condition 1', 'Utilities', 'Electrical', 'Exter Cond', 'Land Slope', 'Heating QC', 'Bsmt Exposure']