Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'str' object has no attribute 'decode'. Did you mean: 'encode'? #422

Open
makoeppel opened this issue Nov 28, 2022 · 0 comments

Comments

@makoeppel
Copy link

There is a problem in the file aif360/sklearn/preprocessing/learning_fair_representations.py:167 the function scipy.optimize.minimize returns a OptimizeResult which has the attribute message which is already a str object. So the program will file with:

AttributeError: 'str' object has no attribute 'decode'. Did you mean: 'encode'?

Quite a constructed example but this does fail with the error code above. I use aif360==0.5.0 and tried scipy==1.8.1, scipy==1.9.0 and scipy==1.9.1. Fix is trivial just change:

warnings.warn('lbfgs failed to converge: {}'.format(
              res.message.decode()), ConvergenceWarning)

to

warnings.warn('lbfgs failed to converge: {}'.format(
              res.message), ConvergenceWarning)
from aif360.sklearn.preprocessing import LearnedFairRepresentations
import pandas as pd

x = pd.DataFrame(
    [[1, 0.030671, -1.063611, 1.134739,  0.148453],
    [1, 0.837109, -1.008707, 1.134739,  -0.145920],
    [1, -0.042642, 0.245079, -0.420060, -0.145920],
    [1, 1.057047,  0.425801, -1.197459, -0.145920],
    [1, 0.775768,  1.408176, 1.134739,  -0.145920],
    [1, -0.115955, 0.898201, 1.523438,  -0.145920],
    [1, 0.763796, -0.280358, -1.974858, -0.145920],
    [1, 0.983734,  0.188195, -0.420060, -0.145920],
    [1, -0.555830,-1.364279, 1.523438,  1.761142],
    [1, 0.250608, -0.287350, 1.134739,  0.555214]],
    columns=["sex", "1", "2", "3", "4"]
)
x.set_index("sex", inplace=True)
y = pd.DataFrame([0, 0, 0, 0, 0, 0, 0, 1, 1, 1])

model = LearnedFairRepresentations(
    n_prototypes=5,
    reconstruct_weight=1,
    target_weight=1,
    fairness_weight=1,
    verbose=2,
    prot_attr='sex'
)

model.fit(x, y, priv_group=1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant