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

Scale function bug? #2

Open
chern1990 opened this issue Apr 19, 2024 · 0 comments
Open

Scale function bug? #2

chern1990 opened this issue Apr 19, 2024 · 0 comments

Comments

@chern1990
Copy link

chern1990 commented Apr 19, 2024

Is the else condition indented wrongly?

def scale_value(value_dict):
    """
    Calculate and return a dict of the value of input dict scaled to (0, 1)
    """

    ranked_dict = [(user, value_dict[user]) for user in value_dict.keys()]
    ranked_dict = sorted(ranked_dict, reverse=True, key=lambda x: x[1])

    up_max, up_mean, up_min = ranked_dict[0][1], ranked_dict[int(len(ranked_dict) / 2)][1], ranked_dict[-1][1]

    scale_dict = {}
    for i, p in value_dict.items():
        norm_value = (p - up_min) / (up_max - up_min)
        if norm_value == 0:  # avoid the 0
            scale_dict[i] = 0 + 1e-7
        elif norm_value == 1:  # avoid the 1
            scale_dict[i] = 1 - 1e-7
    else:
        scale_dict[i] = norm_value

    return scale_dict
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