Skip to content

A line in ID3Tree#id3_continuous has no effect #21

Description

@elestrade

Thank you Ilya for your great job. I work with @nicomahler and we look forward contributing to this project.

As I worked on #19, I remarked that the last line of the code snippet below, extracted from ID3Tree#id3_continuous (line 117 in id3_tree.rb) seems to have no effect at all:

    gain = thresholds.collect { |threshold|
      (...)
      [data.classification.entropy - pos*sp[0].classification.entropy - neg*sp[1].classification.entropy, threshold]
    }.max { |a,b| a[0] <=> b[0] }

    return [-1, -1] if gain.size == 0  # gain.size is never 0, so this line of code has no effect (but will raise exception if gain is nil).

gain is a result of Enumerable#max method applied on an array of 2-elements arrays. Its value is either nil, if the array is empty (case where thresholds is empty - I don't know if it can happen, we never met that case), or a 2-elements array. It can never be an empty array. So gain.size is never 0.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions