mirror of
https://github.com/dkam/decisiontree.git
synced 2025-12-28 07:04:53 +00:00
convert labels to string - closes #13
This commit is contained in:
@@ -42,6 +42,7 @@ module DecisionTree
|
|||||||
end
|
end
|
||||||
|
|
||||||
def train(data=@data, attributes=@attributes, default=@default)
|
def train(data=@data, attributes=@attributes, default=@default)
|
||||||
|
attributes = attributes.map {|e| e.to_s}
|
||||||
initialize(attributes, data, default, @type)
|
initialize(attributes, data, default, @type)
|
||||||
|
|
||||||
# Remove samples with same attributes leaving most common classification
|
# Remove samples with same attributes leaving most common classification
|
||||||
|
|||||||
@@ -89,4 +89,20 @@ describe describe DecisionTree::ID3Tree do
|
|||||||
Then { tree.predict(["a1","b0","c0"]).should == "RED" }
|
Then { tree.predict(["a1","b0","c0"]).should == "RED" }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "numerical labels case" do
|
||||||
|
Given(:labels) { [1, 2] }
|
||||||
|
Given(:data) do
|
||||||
|
[
|
||||||
|
[1, 1, true],
|
||||||
|
[1, 2, false],
|
||||||
|
[2, 1, false],
|
||||||
|
[2, 2, true]
|
||||||
|
]
|
||||||
|
end
|
||||||
|
Given(:tree) { DecisionTree::ID3Tree.new labels, data, nil, :discrete }
|
||||||
|
When { tree.train }
|
||||||
|
Then {
|
||||||
|
lambda { tree.predict([1, 1]) }.should_not raise_error
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user