Skip to content

Commit

Permalink
Update label query
Browse files Browse the repository at this point in the history
  • Loading branch information
mannbach committed Sep 11, 2024
1 parent d648fba commit 4c33c31
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion netin/stats/distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def get_disparity(df: pd.DataFrame, x: str, total: float = None) -> (np.ndarray,

gx, gy = get_gini_coefficient(df, x, total)
fx, fy = get_fraction_of_minority(df, x, total)
f_m = df.query("class_label == @const.MINORITY_LABEL").shape[0] / df.shape[0]
f_m = df.query("real_label == @const.MINORITY_LABEL").shape[0] / df.shape[0]

inequality_y = ranking.get_ranking_inequality(gy)
inequity_x = ranking.get_ranking_inequity(f_m, fy)
Expand Down
7 changes: 4 additions & 3 deletions netin/stats/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ def get_node_metadata_as_dataframe(
.get_node_class(node_class_values)
class_values = node_class_values.get_class_values()

obj = {'node': list(graph.nodes()),
'class_label': [node_class_values[n] for n in graph.nodes()],
'real_label': [class_values[n] for n in graph.nodes()]}
l_nodes = list(graph.nodes())
obj = {'node': l_nodes,
'class_label': [node_class_values[n] for n in l_nodes],
'real_label': [class_values[n] for n in l_nodes]}

# include graph metadata
if include_graph_metadata:
Expand Down
2 changes: 1 addition & 1 deletion netin/stats/ranking.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def get_fraction_of_minority_in_ranking(df: pd.DataFrame, x: str) -> \
column = f"{x}_rank"
tmp = df.query(f"{column} <= @rank").copy()
total = tmp.shape[0]
efm = np.nan if total == 0 else tmp.query("class_label == @const.MINORITY_LABEL").shape[0] / total
efm = np.nan if total == 0 else tmp.query("real_label == @const.MINORITY_LABEL").shape[0] / total
ys.append(efm)
return xs, ys

Expand Down
4 changes: 2 additions & 2 deletions netin/viz/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ def plot_distribution(data: Union[pd.DataFrame, List[pd.DataFrame]],

class_label: str
iter_groups = df.groupby(hue) if hue is not None else [(None, df)]
f_m = df.query("class_label == @const.MINORITY_LABEL").shape[0] / df.shape[0]
f_m = df.query("real_label == @const.MINORITY_LABEL").shape[0] / df.shape[0]
for class_label, group in iter_groups:
total = df[_col_name].sum()\
if common_norm else group[_col_name].sum()
Expand Down Expand Up @@ -717,7 +717,7 @@ def get_me_label(f_m, ys, beta=None) -> Tuple[str, float, str]:

def show_minority(axline, data):
axline(
data.query("class_label==@const.MINORITY_LABEL")\
data.query("real_label==@const.MINORITY_LABEL")\
.shape[0] / data.shape[0],
color="black", linestyle='--')

Expand Down

0 comments on commit 4c33c31

Please sign in to comment.