Skip to content

Scale function bug? #2

Description

@chern1990

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions