Skip to content

Commit

Permalink
improve pep style
Browse files Browse the repository at this point in the history
  • Loading branch information
anpolol committed Dec 4, 2023
1 parent 620a7b9 commit 03c74e8
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 17 deletions.
2 changes: 1 addition & 1 deletion stable_gnn/explain.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,4 @@ def _search_m_k(data: pd.DataFrame, target: str, nodes: List[str]) -> List[str]:
if count == len(m_b):
return m_b
else:
return m_b
return m_b
23 changes: 9 additions & 14 deletions stable_gnn/fairness.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
from sklearn.linear_model import LogisticRegression
from sklearn.tree import DecisionTreeClassifier
from sklearn.svm import SVC
from sklearn.neighbors import KNeighborsClassifier

import numpy as np
import pandas as pd
from scipy.optimize import linprog
from sklearn.model_selection import train_test_split
from sklearn.base import BaseEstimator
from sklearn.ensemble import RandomForestClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
from sklearn.base import BaseEstimator
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
from sklearn.svm import SVC
from sklearn.tree import DecisionTreeClassifier


class Fair:
Expand All @@ -34,7 +33,7 @@ def run(
random_state: int = None,
):
"""
Main function running fairness correction and calculating accuracy and fairness values
Correct fairness and calculate accuracy and fairness values
:param number_iterations: (int) Number of iterations of interior algorithm
:param prefit: (bool) Flag if passed estimator fitted already or not (default: False)
Expand Down Expand Up @@ -91,7 +90,7 @@ def _ml_model(self, df, random_state, estimator, prefit):
x = df["target"]

y_train, y_test, x_train, x_test = train_test_split(y, x, random_state=random_state)
if prefit == False:
if prefit is False:
estimator.fit(y_train, x_train)
estimator_pred = estimator.predict(y_test)
accuracy_estimator = accuracy_score(estimator_pred, x_test)
Expand Down Expand Up @@ -161,13 +160,9 @@ def _lp_solver(
multiplier=1,
random_state=None,
):
group = multiplier * d["group"]
one_group = multiplier * d["one_group"]
zero_group = multiplier * d["zero_group"]

one_train_probs = d["one_train_probs"]
zero_train_probs = d["zero_train_probs"]

bounds = []
for i in range(3 * one_group + 3 * zero_group):
bounds.append((0, 1))
Expand All @@ -193,7 +188,7 @@ def _lp_solver(
if verbose:
print("Start fitting")
for k in range(number_iterations):
if random_state == None:
if random_state is None:
one_sample = d["one_train_probs"].sample(one_group)
zero_sample = d["zero_train_probs"].sample(zero_group)
else:
Expand Down
2 changes: 1 addition & 1 deletion stable_gnn/model_gc.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,4 +293,4 @@ def self_supervised_loss(deg_pred: Tensor, batch: Batch) -> Tensor:
batch_ptr.numpy()[1:] - batch_ptr.numpy()[: len(batch_ptr) - 1]
) # после экстраполяции мы получили очень плотный граф, хотим степень снизить в N раз для более хороших предсказаний
true = degree(batch.edge_index[0], batch.x.shape[0])[indices] / ratio
return F.mse_loss(deg_pred, true)
return F.mse_loss(deg_pred, true)
3 changes: 2 additions & 1 deletion tests/test_general/test_fairness.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import numpy as np
import pandas as pd
from stable_gnn.fairness import Fair
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split

from stable_gnn.fairness import Fair


def synthetic_dataset(size=1000, influence=True):
"""
Expand Down
Empty file.
34 changes: 34 additions & 0 deletions tutorials/tutorial_link_prediction.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

0 comments on commit 03c74e8

Please sign in to comment.