Skip to content

Commit 06ca9cf

Browse files
committed
get pareto points function
1 parent e7da3d0 commit 06ca9cf

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

fomo/estimator.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import math
3535
import uuid
3636
import numpy as np
37+
import pandas as pd
3738
from sklearn.base import BaseEstimator, ClassifierMixin, RegressorMixin
3839
from sklearn.utils.validation import check_X_y, check_array, check_is_fitted
3940
from sklearn.utils.multiclass import unique_labels
@@ -339,11 +340,7 @@ def plot(self):
339340
check_is_fitted(self, 'is_fitted_')
340341
I = self.I_
341342
F = self._get_signed_F()
342-
axis_labels = (
343-
[ am._score_func.__name__ for am in self.accuracy_metrics_ ]
344-
+ [ fn.__name__ for fn in self.fairness_metrics_ ]
345-
)
346-
axis_labels = [al.replace('_',' ') for al in axis_labels]
343+
axis_labels = self._get_objective_names()
347344
plot = (
348345
Scatter()
349346
.add(F, alpha=0.2, label='Candidate models')
@@ -367,12 +364,21 @@ def _get_signed_F(self, F=None):
367364
F[:,i] = F[:,i]*m._sign
368365
return F
369366

367+
def _get_objective_names(self):
368+
"""Returns names of functions defining the objectives"""
369+
labels = (
370+
[ m._score_func.__name__ for m in self.accuracy_metrics_ ]
371+
+ [ fn.__name__ for fn in self.fairness_metrics_ ]
372+
)
373+
labels = [l.replace('_',' ') for l in labels]
374+
return labels
375+
370376
def get_pareto_points(self):
371377
"""Return a Pandas dataframe of the Pareto archive points"""
372-
archive = pd.DataFrame(
373-
self._get_signed_F(),
374-
columns=self.accuracy_metrics_ + self.fairness_metrics_
375-
)
378+
F = self._get_signed_F()
379+
I = self.I_
380+
archive = pd.DataFrame(F, columns=self._get_objective_names())
381+
archive['chosen'] = [all(f==F[I]) for f in F]
376382
return archive
377383

378384
class FomoClassifier(FomoEstimator, ClassifierMixin, BaseEstimator):

0 commit comments

Comments
 (0)