API Reference

Note

This section documents the public API of the co2_emissions_ml package. For tutorials and usage examples, see Tutorial.

Modules

co2_emissions_ml.preprocessing.build_preprocessor(X: DataFrame) ColumnTransformer[source]

Construct a ColumnTransformer that scales numeric features and one-hot encodes categoricals.

co2_emissions_ml.preprocessing.build_target_transformer() PowerTransformer[source]

Returns a Yeo–Johnson power transformer for the target variable.

co2_emissions_ml.models.fit_cluster_model(X, y, preprocessor, target_transformer, n_trials=60)[source]

Fit the stacked ensemble (3 GBMs + MLP meta-learner + Ridge residuals). Returns a dict bundling all fitted elements.

co2_emissions_ml.models.predict_bundle(bundle, X_new)[source]

Given a fitted bundle, return inverse‐transformed predictions for new X.

co2_emissions_ml.evaluation.compute_metrics(y_true, y_pred)[source]

Returns a dict of common regression metrics.

co2_emissions_ml.evaluation.segment_metrics(df, group_col, y_true_col='true_CO2', y_pred_col='pred_CO2')[source]

Compute metrics per unique value in group_col of df. Returns a DataFrame with columns [group_col, Count, R2, MAE, RMSE].

co2_emissions_ml.pipeline.main()[source]
co2_emissions_ml.pipeline.run_pipeline(data_path: str, target_col: str | None = None)[source]