You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using the provided code to compute SPD (Statistical Parity Difference) on adult datasets. However, upon calling the function get_spd_and_accuracy within a loop, I've noticed that memory consumption gradually increases when class_metrics.statistical_parity_difference() is instantiated with each iteration, and this memory is not being released at the end of each iteration.
from aif360.datasets import AdultDataset, GermanDataset, CompasDataset
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from aif360.datasets import StandardDataset, BinaryLabelDataset
from aif360.metrics import ClassificationMetric
from copy import deepcopy
from sklearn.metrics import accuracy_score
def get_spd_and_accuracy(df, protected, target):
'''Prepare the data for training and testing'''
train, test = train_test_split(df, test_size=0.2, shuffle=True)
X_train = train.drop([protected, target], axis=1).values
y_train = train[target].values
y_test = test[target].values
X_test = test.drop([protected, target], axis=1).values
'''Train the model and predict the labels for the training and testing data'''
lmod = LogisticRegression(solver='liblinear', class_weight='balanced')
lmod.fit(X_train,y_train)
y_train_pred = lmod.predict(X_train)
y_test_pred = lmod.predict(X_test)
'''Prepare the data for the AIF360 metrics'''
train_transf = StandardDataset(train,
label_name=target,
favorable_classes=[1],
protected_attribute_names=[protected],
categorical_features=[],
features_to_drop=[],
privileged_classes=[[1.0]])
train_transf_pred = deepcopy(train_transf)
train_transf_pred.labels = y_train_pred
un_p=[{protected:0.0}]
p=[{protected:1.0}]
'''Calculate the Statistical Parity Difference and Accuracy Score'''
class_metrics = ClassificationMetric(train_transf,train_transf_pred,unprivileged_groups=un_p, privileged_groups=p)
print(round(class_metrics.statistical_parity_difference(),2))
print(round(accuracy_score(y_test, y_test_pred),2))
dataset = AdultDataset()
df = dataset.convert_to_dataframe()[0]
target = df.columns[-1]
protected = 'sex'
for i in range(25):
get_spd_and_accuracy(df, protected, target)
Any insights or recommendations regarding memory release strategies in this context would be greatly appreciated. Below is the snapshot of increase in memory.
Before executing the code
During the execution of the code
The text was updated successfully, but these errors were encountered:
trivedi-nitesh
changed the title
Incorrect Memory Management in AIF's ClassificationMetric Class Persists Beyond Function Termination
Memory Management Issue in ClassificationMetric Class Persists Beyond Function Termination
Apr 19, 2024
trivedi-nitesh
changed the title
Memory Management Issue in ClassificationMetric Class Persists Beyond Function Termination
Memory Management Issue in class ClassificationMetric
Apr 19, 2024
I'm using the provided code to compute SPD (Statistical Parity Difference) on adult datasets. However, upon calling the function get_spd_and_accuracy within a loop, I've noticed that memory consumption gradually increases when
class_metrics.statistical_parity_difference()
is instantiated with each iteration, and this memory is not being released at the end of each iteration.Any insights or recommendations regarding memory release strategies in this context would be greatly appreciated. Below is the snapshot of increase in memory.
Before executing the code
![Screenshot from 2024-04-19 10-59-07](https://private-user-images.githubusercontent.com/59827743/323848306-1561c1c5-e8df-4405-a414-0045e6ce6140.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU2NjM3OTMsIm5iZiI6MTcyNTY2MzQ5MywicGF0aCI6Ii81OTgyNzc0My8zMjM4NDgzMDYtMTU2MWMxYzUtZThkZi00NDA1LWE0MTQtMDA0NWU2Y2U2MTQwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MDYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTA2VDIyNTgxM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTUxYTcxNTI5YzhmMzU3NTQzNzAzMjZmMjFjOTkxNzM1OWU4YjMzMWUwYjk2ZDkxNDBjZWQ4NjgzOTA5NWNkNjAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.HFpy0XJm9tS-plomvbfKhgMWuRH83yIUeSQNq1F94yY)
During the execution of the code
![Screenshot from 2024-04-19 11-03-13](https://private-user-images.githubusercontent.com/59827743/323848529-3ca70d20-df0c-4ff1-9403-0cad517f9cca.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU2NjM3OTMsIm5iZiI6MTcyNTY2MzQ5MywicGF0aCI6Ii81OTgyNzc0My8zMjM4NDg1MjktM2NhNzBkMjAtZGYwYy00ZmYxLTk0MDMtMGNhZDUxN2Y5Y2NhLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MDYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTA2VDIyNTgxM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTc5MTBhNWIyZWI4MWNkNzc2MDgyMmYyMGE5YzM4YzcwNjcyMDRmZTIzYThmNTQ4ODZiZDIzNGZmZGM3MWI5MmUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.P5EF2WLl2v8beNI0_q3G1s_Pir1zOWDHjyZU2-WP3Dc)
The text was updated successfully, but these errors were encountered: