Skip to content

Commit

Permalink
starting implementing deepar with mlflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ivargr committed Sep 5, 2024
1 parent 588f412 commit 0414122
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
5 changes: 4 additions & 1 deletion climate_health/external/external_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ def predict(self, future_data: IsSpatioTemporalDataSet[FeatureType]) -> IsSpatio
df = future_data.to_pandas()
df['disease_cases'] = np.nan

# todo: instead of using saved state for historic data, get histori data in as argument to predict
# send historic data and future data as two seperate data sets to model

new_pd = self._adapt_data(df)
if self.is_lagged:
new_pd = pd.concat([self._saved_state, new_pd]).sort_values(['location', 'time_period'])
Expand Down Expand Up @@ -413,7 +416,7 @@ def get_model_from_mlproject_file(mlproject_file):
adapters = config.get('adapters', None)
allowed_data_types = {'HealthData': HealthData}
data_type = allowed_data_types.get(config.get('data_type', None), None)
return ExternalMLflowModel(mlproject_file, name=name, adapters=adapters, data_type=data_type,
return ExternalMLflowModel(mlproject_file.parent, name=name, adapters=adapters, data_type=data_type,
working_dir=Path(mlproject_file).parent)


Expand Down
4 changes: 2 additions & 2 deletions climate_health/external/mlflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(self, model_path: str, name: str=None, adapters=None, working_dir="
@property
def name(self):
return self._name

def __call__(self):
return self

Expand All @@ -55,7 +55,7 @@ def train(self, train_data: DataSet, extra_args=None):
response = mlflow.projects.run(str(self.model_path), entry_point="train",
parameters={
"train_data": str(train_file_name),
"model_output_file": str(self._model_file_name)
"model": str(self._model_file_name)
},
build_image=True)
self._saved_state = new_pd
Expand Down
22 changes: 22 additions & 0 deletions external_models/deepar/MLproject
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: My Project

# python_env: python_env.yaml
# or
# conda_env: my_env.yaml
# or
# docker_env:
# image: mlflow-docker-example

entry_points:
train:
parameters:
train_data: path
model: path
command: "ch_modelling train {train_data} {model}"
predict:
parameters:
model: path
historic_data: path
future_data: path
out_file: path
command: "ch_modelling predict {model} {historic_data} {future_data} {out_file}"
1 change: 1 addition & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ earthengine-api
python-dotenv
myst_parser
furo
virtualenv

0 comments on commit 0414122

Please sign in to comment.