Skip to content
All posts

What I Learned Building an ML Pipeline with scikit-learn for EcoPackAI

Uttam Verma··10 min read
PythonMachine LearningFlaskPostgreSQL

EcoPackAI started as a hackathon idea: what if businesses could predict the cost and environmental impact of their packaging choices before committing to them?

The ML pipeline has three stages: data preprocessing with pandas, feature engineering, and prediction using scikit-learn models. The preprocessing stage handles missing values, normalizes numerical features, and encodes categorical variables like packaging material type and shipping region.

Feature engineering was where the real work happened. Raw packaging dimensions don't tell you much on their own, but derived features like surface area, volume-to-weight ratio, and material density turned out to be strong predictors of both cost and CO₂ impact.

I trained separate models for cost prediction and environmental impact. For cost, a gradient boosting regressor performed best. For CO₂ estimation, I used a random forest — it handled the non-linear relationships between material type and emissions better than linear models.

The biggest challenge was data quality. Real-world packaging data is messy. Inconsistent units, missing fields, outliers from data entry errors. I spent more time cleaning data than training models, which is apparently normal — but nobody tells you that when you're starting out.

Serving the model through Flask was straightforward. The trained models are serialized with joblib and loaded when the Flask app starts. Each prediction request deserializes the input, runs it through the same preprocessing pipeline used during training, and returns both the cost and CO₂ predictions.

PostgreSQL stores the prediction history so users can compare different packaging options over time. SQLAlchemy made the database layer clean — define the models once, and the ORM handles the rest.

What I'd do differently next time: spend more time on data validation upfront, use a proper experiment tracking tool like MLflow instead of Jupyter notebooks, and add confidence intervals to predictions so users know how certain the model is.