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:
BaseLinearDROLinear 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_idxofX. The column must contain finite, discrete numeric values. It remains part ofXduring fitting and prediction, which keeps the usualfit(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.
- fit(X, y)¶
Fit by minimizing the maximum empirical group loss.
- Parameters:
X (numpy.ndarray) – Numeric feature matrix of shape
(n_samples, input_dim). Columngroup_idxsupplies 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_lossesalign withgroup_values.- Return type:
Dict[str, Any]