final full model + streaming data from disk #33
No reviewers
Labels
No labels
CI/CD
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
tests
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
AndreFerreira5/downtown-cab-co!33
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "pipeline-overhaul"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Pull request overview
This PR introduces a unified MLflow model wrapper for the two-stage prediction system (trend model + residual booster) and refactors the data loading mechanism to stream parquet files directly from disk using PyArrow instead of loading entire files into memory.
TrendResidualModelclass wrapping both Ridge and LightGBM models as a single MLflow pyfunc modelDataLoaderto use PyArrow'siter_batchesfor memory-efficient streaming from parquet filespredictingflag to preprocessor to handle differences between training and inference data availabilityReviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 12 comments.
Comments suppressed due to low confidence (2)
src/training_api/main.py:19
src/training_api/main.py:3
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Missing import:
pq(pyarrow.parquet) is used here but not imported. Addimport pyarrow.parquet as pqat the top of the file to fix theNameError.Missing docstring: The
resetmethod no longer has a docstring after the refactoring. Consider adding one to explain its purpose, e.g., "Reset the loader to start from the beginning and clear memory."Missing docstring: The
get_file_countmethod no longer has a docstring after the refactoring. Consider adding one to explain its purpose, e.g., "Return the number of parquet files."@ -1,6 +1,8 @@import loggingimport pandas as pdUnused import:
pandas as pdis imported but not used in this file. Consider removing it to keep imports clean.@ -20,0 +21,4 @@with open(context.artifacts["regressor"], "rb") as f:self.trend_model = pickle.load(f)with open(context.artifacts["booster"], "rb") as f:self.booster_model = pickle.load(f)Inconsistent attribute naming: The loaded model is stored as
self.trend_modelbut later referenced asself.model_ain line 30. This will cause anAttributeErrorat runtime. Change this toself.trend_modelto match the usage in the predict method.@ -20,0 +23,4 @@with open(context.artifacts["booster"], "rb") as f:self.booster_model = pickle.load(f)def predict(self, context, model_input):Inconsistent attribute naming: The loaded model is stored as
self.booster_modelbut later referenced asself.model_bin line 34. This will cause anAttributeErrorat runtime. Change this toself.booster_modelto match the usage in the predict method.@ -20,0 +27,4 @@model_input["tpep_pickup_datetime"] = pd.to_datetime(model_input["tpep_pickup_datetime"])(X, t) = preprocess_taxi_data(pd.DataFrame([model_input]), remove_outliers=False, create_features=True, predicting=True)trend_pred = self.model_a.predict(X[['date_int', 'sin_time', 'cos_time']])Incorrect unpacking:
preprocess_taxi_datareturns a tuple of(pd.DataFrame, TaxiDataPreprocessor), not(X, t). The second element is the preprocessor object, not a target variable. This line should be:X, _ = preprocess_taxi_data(...)orX = preprocess_taxi_data(...)[0].@ -20,0 +29,4 @@trend_pred = self.model_a.predict(X[['date_int', 'sin_time', 'cos_time']])trend_pred = np.maximum(trend_pred, 1.0)Incorrect attribute reference: Using
self.model_abut the attribute is defined asself.trend_modelin line 22. Change toself.trend_modelto match the load_context method.@ -20,0 +32,4 @@X.drop(columns=['trip_duration', 'tpep_pickup_datetime', 'date_int', 'sin_time', 'cos_time'], errors='ignore')ratio_pred = self.model_b.predict(X)final_pred = trend_pred * ratio_predMissing assignment: The
dropmethod returns a new DataFrame and doesn't modify in place. The result is not being assigned toX, so the columns are not actually removed. Change to:X = X.drop(columns=[...], errors='ignore').@ -20,0 +33,4 @@X.drop(columns=['trip_duration', 'tpep_pickup_datetime', 'date_int', 'sin_time', 'cos_time'], errors='ignore')ratio_pred = self.model_b.predict(X)final_pred = trend_pred * ratio_predIncorrect attribute reference: Using
self.model_bbut the attribute is defined asself.booster_modelin line 24. Change toself.booster_modelto match the load_context method.Missing cleanup: The pickle files created at
regressor_pathandbooster_pathare not cleaned up after logging the model to MLflow (unlike inrun_trainingwhere they are removed on lines 438-439). This creates temporary files that persist in the filesystem during hyperparameter tuning. Consider adding cleanup after line 378:Multiple statements on one line: Consider splitting this into separate lines for better readability: