Compare commits

...

30 commits

Author SHA1 Message Date
KhalimCK
f99c0aee2c
Merge pull request #96 from Hestia-Homes/carbon-dev-model
Carbon dev model
2024-01-30 10:38:05 +00:00
Michael Duong
76d414417a Merge branch 'carbon-dev' of github.com:Hestia-Homes/ML into carbon-dev-model 2024-01-30 10:26:43 +00:00
Michael Duong
1887a52230 use new modesl with carbon model 2024-01-30 10:26:28 +00:00
Github-Bot
9880ebed4c Update Registry 2024-01-18 10:38:17 +00:00
Github-Bot
5d23992d05 Update Registry 2024-01-18 10:37:29 +00:00
KhalimCK
d4836e02cb
Merge pull request #92 from Hestia-Homes/carbon-dev-model
Carbon dev model
2024-01-18 10:36:46 +00:00
Michael Duong
9b29e838af update requirements for dvc 2024-01-17 23:45:07 +00:00
Michael Duong
79a55ba8b5 train 600 second model on new data 2024-01-17 23:35:50 +00:00
Michael Duong
e78a4bb30e Merge branch 'carbon-dev' of github.com:Hestia-Homes/ML into carbon-dev-model 2024-01-17 23:12:26 +00:00
Michael Duong
ae53499742 add keep only non negative carbon change to carbon model 2023-12-22 09:51:57 +00:00
Github-Bot
db29bece80 Update Registry 2023-11-28 15:27:34 +00:00
Github-Bot
65335468b4 Update Registry 2023-11-28 15:26:50 +00:00
quandanrepo
53afbd26d8
Merge pull request #88 from Hestia-Homes/carbon-dev-model
Carbon dev model
2023-11-28 15:26:04 +00:00
Michael Duong
718003b3d9 Merge branch 'carbon-dev' of github.com:Hestia-Homes/ML into carbon-dev-model 2023-11-28 15:14:09 +00:00
Michael Duong
888bfc30c6 Merge branch 'master' of github.com:Hestia-Homes/ML into carbon-dev-model 2023-11-28 15:13:50 +00:00
Michael Duong
2b1e8b912b restrict dataset 2023-11-28 15:13:42 +00:00
Github-Bot
62f2f83b0a Update Registry 2023-11-27 19:22:00 +00:00
Github-Bot
03322a13e7 Update Registry 2023-11-27 19:21:22 +00:00
KhalimCK
5f3d9efa92
Merge pull request #85 from Hestia-Homes/carbon-dev-model
Carbon dev model
2023-11-27 19:20:40 +00:00
Michael Duong
f29d6af6a2 change readme 2023-11-27 19:13:23 +00:00
Michael Duong
7afc4b06b2 Merge branch 'master' of github.com:Hestia-Homes/ML into carbon-dev-model 2023-11-27 19:12:40 +00:00
Michael Duong
217fb3dca8 add inference speed check 2023-11-27 18:52:47 +00:00
Michael Duong
9a04ffde3b Merge branch 'master' of github.com:Hestia-Homes/ML into carbon-dev-model 2023-11-27 18:30:10 +00:00
Michael Duong
e6c7b2f58c Merge branch 'carbon-dev' of github.com:Hestia-Homes/ML into carbon-dev-model 2023-10-12 08:39:24 +00:00
Michael Duong
f2cc32f4b4 using good model 4000s 2023-10-12 08:38:55 +00:00
Github-Bot
2f9092f447 Update Registry 2023-10-11 15:48:52 +00:00
Github-Bot
bb2db16f61 Update Registry 2023-10-11 15:48:04 +00:00
quandanrepo
5aaebd7f44
Merge pull request #71 from Hestia-Homes/carbon-dev-model
400 second model
2023-10-11 16:47:13 +01:00
Michael Duong
680e879503 400 second model 2023-10-11 15:38:55 +00:00
Michael Duong
f4e91162ec initial model 2023-10-11 13:23:54 +00:00
12 changed files with 152 additions and 64 deletions

View file

@ -8,17 +8,25 @@
"active": true
},
"sap": {
"version": "v0.1.0",
"version": "v0.4.0",
"stage": {
"dev": "v0.1.0"
"dev": "v0.4.0"
},
"registered": true,
"active": true
},
"heat": {
"version": "v0.0.1",
"version": "v0.3.0",
"stage": {
"dev": "v0.0.1"
"dev": "v0.3.0"
},
"registered": true,
"active": true
},
"carbon": {
"version": "v0.3.0",
"stage": {
"dev": "v0.3.0"
},
"registered": true,
"active": true

View file

@ -1,3 +1,3 @@
# The generic reproducible ML-pipeline
# The generic reproducible ML-pipeline!
Pipeline required to build a model to produce an output, that gets hashed via DVC

View file

@ -87,7 +87,8 @@ def prepare_data(
if train_proportion == 1:
train = data
test = None
# Sample 10% of the data for testing
test = data.sample(round(len(data) * 0.1))
else:
train, test = train_test_split(
data, train_size=train_proportion, test_size=(1 - train_proportion)

View file

@ -26,9 +26,12 @@ prepare_data_params = settings.prepare_data
build_model_params = settings.build_model
feature_process_params = settings.feature_processor
generate_metrics_params = settings.generate_metrics
generate_predictions_params = settings.generate_predictions
model_type = build_model_params["model_type"]
target = feature_process_params["feature_processor_config"]["target"]
fit_predictions_filepath = build_model_params["fit_predictions_filepath"]
predictions_column_name = generate_predictions_params["predictions_column_name"]
identifier_columns = feature_process_params["feature_processor_config"][
"identifier_columns"
]
@ -60,6 +63,8 @@ def build_model(
identifier_columns: List[str],
model_save_location: str,
model_hyperparameters: dict,
fit_predictions_filepath: str,
predictions_column_name: str,
fit_metrics_filepath: str,
train_filepath: Union[str, None] = None,
test_filepath: Union[str, None] = None,
@ -93,6 +98,15 @@ def build_model(
data=train_data, post_prediction_logic=post_prediction_logic
)
logger.info("--- Saving fit predictions ---")
predictions_df = pd.DataFrame(fit_predictions)
predictions_df.columns = [predictions_column_name]
dataclient.save_data(
obj=predictions_df, location=fit_predictions_filepath, save_config=None
)
logger.info("--- Generating fit metrics ---")
metrics_output = metrics.generate_metrics(
@ -128,6 +142,8 @@ if __name__ == "__main__":
train_filepath=train_filepath,
test_filepath=test_filepath,
fit_metrics_filepath=fit_metrics_filepath,
fit_predictions_filepath=fit_predictions_filepath,
predictions_column_name=predictions_column_name,
)
logger.info(f"--- {__file__} - Complete! ---")

View file

@ -3,6 +3,7 @@ default:
model_type: AutogluonAutoML
model_save_filepath: ./data/model/optimised/
fit_metrics_filepath: ./metrics/fit_metrics.json
fit_predictions_filepath: ./data/fit_predictions/predictions.parquet
SKLearnLinearRegression: null
@ -15,6 +16,6 @@ default:
eval_metric: mean_squared_error #mean_absolute_error
time_limit: 4000
presets: medium_quality
excluded_model_types: ['KNN', 'RF']
excluded_model_types: ['RF', 'FASTAI', 'CAT', 'NN_TORCH', 'KNN', 'XT']
infer_limit: 0.05
infer_limit_batch_size: 10000

View file

@ -9,15 +9,56 @@ Business Logic dict + functions
def remove_starting_columns(df):
keep_column_index = [
False if col_name.endswith("_STARTING") else True
False if col_name.endswith("_starting") else True
for col_name in list(df.columns)
]
keep_columns = df.columns[keep_column_index].to_list()
keep_columns.append("SAP_STARTING")
keep_columns.append("sap_starting")
df = df[keep_columns]
return df
def keep_negative_heat_change(df):
df = df[df["heat_demand_change"] < 0]
return df
def keep_non_negative_carbon_ending(df):
df = df[df["carbon_ending"] > 0]
return df
def keep_negative_carbon_change(df):
df = df[df["carbon_change"] < 0]
return df
# TODO: Move to ETL pipeline
def remove_unreasonable_habitable_rooms(df):
"""
Assumption is that proportion of floor area to habitable rooms should be at least 6.5m2
"""
minimum_room_size_index = (
df["total_floor_area_ending"] / df["number_habitable_rooms"] >= 6.5
)
df = df[minimum_room_size_index]
return df
def remove_top_1_percent_heat_demand(df):
# threshold_value = df.describe(percentiles=[0.99])['HEAT_DEMAND_STARTING']['99%']
threshold_value = 860
df = df[df["heat_demand_starting"] < threshold_value]
return df
def remove_top_1_percent_carbon(df):
# threshold_value = df.describe(percentiles=[0.99])['CARBON_STARTING']['99%']
threshold_value = 18
df = df[df["carbon_starting"] < threshold_value]
return df
# def keep_ending_columns(df):
# ending_column_index = [ col_name.endswith("_ENDING") for col_name in list(df.columns)]
# keep_columns = df.columns[ending_column_index].to_list()
@ -27,6 +68,12 @@ def remove_starting_columns(df):
# return df
business_logic = {
"remove_unreasonable_habitable_rooms": remove_unreasonable_habitable_rooms,
"keep_negative_heat_change": keep_negative_heat_change,
"keep_negative_carbon_change": keep_negative_carbon_change,
"remove_top_1_percent_heat_demand": remove_top_1_percent_heat_demand,
"remove_top_1_percent_carbon": remove_top_1_percent_carbon,
"keep_non_negative_carbon_ending": keep_non_negative_carbon_ending
# "remove_starting_columns": remove_starting_columns
# "keep_ENDING_COLUMNS": keep_ending_columns
}

View file

@ -5,17 +5,18 @@ import pandas as pd
def clip_predictions_to_minimum_value(
data: pd.DataFrame, predictions: pd.Series, minimum_value: int = 1
data: pd.DataFrame,
predictions: pd.Series,
) -> pd.Series:
series_name = predictions.name
predictions.name = "predictions"
predictions_df = pd.concat([data, predictions], axis=1)
# We expect all prediction to be atleast one point improvement
replace_index = predictions_df["SAP_STARTING"] + 1 > predictions_df["predictions"]
predictions_df.loc[replace_index, "predictions"] = (
predictions_df.loc[replace_index, "SAP_STARTING"] + minimum_value
)
replace_index = predictions_df["predictions"] > predictions_df["carbon_starting"]
predictions_df.loc[replace_index, "predictions"] = predictions_df.loc[
replace_index, "carbon_starting"
]
predictions_new = predictions_df["predictions"]
predictions_new.name = series_name

View file

@ -21,8 +21,9 @@ default:
# data_filepath: s3://retrofit-data-dev/sap_change_model/dataset_with_differencing.parquet
# data_filepath: s3://retrofit-data-dev/sap_change_model/floor_area_clean_test.parquet
# data_filepath: s3://retrofit-data-dev/sap_change_model/dataset_without_differencing.parquet
data_filepath: s3://retrofit-data-dev/sap_change_model/dataset_test.parquet
train_proportion: 0.9
# data_filepath: s3://retrofit-data-dev/sap_change_model/dataset.parquet
data_filepath: s3://retrofit-datalake-dev/dataset_with0perm_all.parquet
train_proportion: 1
output_train_filepath: ./data/prepared_data/train.parquet
output_test_filepath: ./data/prepared_data/test.parquet
@ -31,9 +32,9 @@ default:
feature_processor_config:
subsample_amount: null
subsample_seed: 0
target: SAP_ENDING
identifier_columns: ["UPRN"]
drop_columns: ["HEAT_DEMAND_CHANGE", "CARBON_CHANGE", "RDSAP_CHANGE", "HEAT_DEMAND_ENDING", "CARBON_ENDING"]
target: carbon_ending
identifier_columns: ["uprn"]
drop_columns: ["heat_demand_change", "carbon_change", "rdsap_change", "heat_demand_ending", "sap_ending"]
# retain_features: ["SAP_STARTING", "TOTAL_FLOOR_AREA_DIFF"]
retain_features: null

View file

@ -5,44 +5,44 @@ stages:
deps:
- path: 1_prepare_data.py
hash: md5
md5: c9f030df733e318b80d1fa91b7732f79
size: 5132
md5: 11a3b8bfdfe199ab7ecc39ccc5652649
size: 4298
params:
configs/settings.yaml:
default.feature_processor.feature_processor_config.drop_columns:
- HEAT_DEMAND_CHANGE
- CARBON_CHANGE
- RDSAP_CHANGE
- HEAT_DEMAND_ENDING
- CARBON_ENDING
- heat_demand_change
- carbon_change
- rdsap_change
- heat_demand_ending
- sap_ending
default.feature_processor.feature_processor_config.retain_features:
default.feature_processor.feature_processor_config.subsample_amount:
default.feature_processor.feature_processor_config.subsample_seed: 0
default.feature_processor.feature_processor_config.target: SAP_ENDING
default.feature_processor.feature_processor_config.target: carbon_ending
default.feature_processor.feature_processor_type: dataframe
default.prepare_data.data_filepath: s3://retrofit-data-dev/sap_change_model/dataset.parquet
default.prepare_data.data_filepath: s3://retrofit-datalake-dev/dataset_with0perm_all.parquet
default.prepare_data.input_dataclient_type: aws-s3
default.prepare_data.output_dataclient_type: local
default.prepare_data.output_test_filepath: ./data/prepared_data/test.parquet
default.prepare_data.output_train_filepath: ./data/prepared_data/train.parquet
default.prepare_data.train_proportion: 0.9
default.prepare_data.train_proportion: 1
outs:
- path: data/prepared_data/
hash: md5
md5: 9ce5c45722da7fc40491b5a4d00daf9e.dir
size: 33881619
md5: 44737880f5437e23143479a7818a3136.dir
size: 36064622
nfiles: 2
build_model:
cmd: python 2_build_model.py
deps:
- path: 2_build_model.py
hash: md5
md5: 84699d208874c52accaff61c6af9bb0a
size: 5359
md5: 090bfb7dbaff39f45784b7fe332a9b8e
size: 4819
- path: data/prepared_data
hash: md5
md5: 9ce5c45722da7fc40491b5a4d00daf9e.dir
size: 33881619
md5: 44737880f5437e23143479a7818a3136.dir
size: 36064622
nfiles: 2
params:
configs/build_model.yaml:
@ -51,6 +51,7 @@ stages:
model_type: AutogluonAutoML
model_save_filepath: ./data/model/optimised/
fit_metrics_filepath: ./metrics/fit_metrics.json
fit_predictions_filepath: ./data/fit_predictions/predictions.parquet
SKLearnLinearRegression:
SKLearnSVMRegression:
kernel: linear
@ -61,34 +62,45 @@ stages:
time_limit: 4000
presets: medium_quality
excluded_model_types:
- KNN
- RF
- FASTAI
- CAT
- NN_TORCH
- KNN
- XT
infer_limit: 0.05
infer_limit_batch_size: 10000
outs:
- path: data/fit_predictions/
hash: md5
md5: 7b74ae1174ae2c7fab03ee0ce0a8ae71.dir
size: 3877514
nfiles: 1
- path: data/model/
hash: md5
md5: 7bb5156243b4db39349e80a01ffecde4.dir
size: 473398662
nfiles: 27
md5: d2ebaa73a894387f85083c49e58637bc.dir
size: 798349514
nfiles: 32
- path: metrics/fit_metrics.json
hash: md5
md5: 2bb16ac67de8778fbc08171d562b34d5
size: 184
md5: 51c9c678bbd19bc9f7e16f0bf5df3fef
size: 229
generate_predictions:
cmd: python 3_generate_predictions.py
deps:
- path: 3_generate_predictions.py
hash: md5
md5: 5ef2856a5a977304f1ec01f9b4205262
size: 3028
md5: 0a70ad4dfe99414a75d1261c75a177b9
size: 2464
- path: data/model
hash: md5
md5: 7bb5156243b4db39349e80a01ffecde4.dir
size: 473398662
nfiles: 27
md5: d2ebaa73a894387f85083c49e58637bc.dir
size: 798349514
nfiles: 32
- path: data/prepared_data
hash: md5
md5: 9ce5c45722da7fc40491b5a4d00daf9e.dir
size: 33881619
md5: 44737880f5437e23143479a7818a3136.dir
size: 36064622
nfiles: 2
params:
configs/settings.yaml:
@ -100,25 +112,25 @@ stages:
outs:
- path: data/predictions/
hash: md5
md5: 0bb3cf991906953def81c8204cdcfaf0.dir
size: 374532
md5: ac0a698f14fb9002b337b1b163997333.dir
size: 638033
nfiles: 1
generate_metrics:
cmd: python 4_generate_metrics.py
deps:
- path: 4_generate_metrics.py
hash: md5
md5: 2c9fb78955a8c19cff0a098976f81d1b
size: 4487
md5: d09a80dd55f1f69e2a832b1991b3c406
size: 3485
- path: data/predictions
hash: md5
md5: 0bb3cf991906953def81c8204cdcfaf0.dir
size: 374532
md5: ac0a698f14fb9002b337b1b163997333.dir
size: 638033
nfiles: 1
- path: data/prepared_data
hash: md5
md5: 9ce5c45722da7fc40491b5a4d00daf9e.dir
size: 33881619
md5: 44737880f5437e23143479a7818a3136.dir
size: 36064622
nfiles: 2
params:
configs/settings.yaml:
@ -128,15 +140,15 @@ stages:
outs:
- path: metrics/metrics.json
hash: md5
md5: 2e13ae67759a64261d03224f1c0d4bf4
size: 185
md5: 47aa4601e71a93163d2cc1b85d0eda91
size: 228
startup_cleanup:
cmd: python 0_startup_cleanup.py
deps:
- path: 0_startup_cleanup.py
hash: md5
md5: fbb7e3b1b98b517c870f3e1df3e7f695
size: 1676
md5: b1b12f6b6393fbf8b83d23684df0a3d4
size: 1220
params:
configs/settings.yaml:
default.startup_cleanup.artefacts: ./data

View file

@ -38,6 +38,7 @@ stages:
- configs/build_model.yaml:
outs:
- data/model/
- data/fit_predictions/
- metrics/fit_metrics.json
always_changed: true
generate_predictions:

View file

@ -1,4 +1,4 @@
dvc==3.18.0
dvc-s3==2.23.0
gto==1.0.4
pyOpenSSL==23.2.0
dvc==3.36.0
dvc-s3==3.0.1
gto==1.6.1
pyOpenSSL==23.3.0