Group DRO

Group distributionally robust linear models.

Group DRO minimizes the largest empirical loss among groups defined by a categorical feature. The group feature stays in the design matrix, so it can also be used by the fitted predictor.

class dro.linear_model.group_dro.GroupDRO(input_dim, group_idx, model_type='svm', fit_intercept=True, solver='MOSEK', kernel='linear')

Bases: BaseLinearDRO

Linear Group Distributionally Robust Optimization model.

For observed groups \(\mathcal{G}\), this model solves

\[\min_{\theta, b}\; \max_{g \in \mathcal{G}} \frac{1}{n_g}\sum_{i:g_i=g}\ell(\theta, b; x_i, y_i).\]

A group is the value in column group_idx of X. The column must contain finite, discrete numeric values. It remains part of X during fitting and prediction, which keeps the usual fit(X, y) API used by the other linear models in this package.

Parameters:
  • input_dim (int) – Number of columns in the input feature matrix.

  • group_idx (int) – Zero-based index of the categorical group feature.

  • model_type (str) – Loss/model type: 'svm', 'logistic', 'ols', or 'lad'.

  • fit_intercept (bool) – Whether to fit an intercept.

  • solver (str) – Installed CVXPY solver used for optimization.

  • kernel (str) – Kernel accepted by BaseLinearDRO.

  • input_dim – Dimensionality of the input features.

  • model_type – Model type indicator (‘svm’ for SVM, ‘logistic’ for Logistic Regression, ‘ols’ for Linear Regression for OLS, ‘lad’ for Linear Regression for LAD), default = ‘svm’.

  • fit_intercept – Whether to calculate the intercept for this model. If set to False, no intercept will be used in calculations (i.e. data is expected to be centered), default = True.

  • solver – Optimization solver to solve the problem, default = ‘MOSEK’.

  • kernel – the kernel type to be used in the optimization model, default = ‘linear’

Variables:
  • group_values – Sorted group categories observed by the latest call to fit().

  • group_losses – Empirical loss for each value in group_values_ at the fitted solution.

  • robust_loss – Largest fitted group loss.

update(config)

Update the feature used to define groups.

Parameters:

config (Dict[str, Any]) – Configuration dictionary. group_idx is the only Group DRO-specific key; unrelated keys are ignored consistently with the other linear model implementations.

Return type:

None

fit(X, y)

Fit by minimizing the maximum empirical group loss.

Parameters:
  • X (numpy.ndarray) – Numeric feature matrix of shape (n_samples, input_dim). Column group_idx supplies the finite group categories.

  • y (numpy.ndarray) – Binary labels in {-1, +1} for classification, or numeric targets for regression.

Returns:

Fitted parameters and group-loss diagnostics. The entries in group_losses align with group_values.

Return type:

Dict[str, Any]