Skip to content

Commit 3fe2e37

Browse files
authored
Merge pull request #94 from bensadeghi/cleanup
Little Cleanup
2 parents 9a6d9e5 + 4690b07 commit 3fe2e37

File tree

7 files changed

+56
-173
lines changed

7 files changed

+56
-173
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ os:
55

66
julia:
77
- 0.7
8-
- 1.0
8+
- 1.1
99
- nightly
1010

1111
matrix:

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
[![Build Status](https://travis-ci.org/bensadeghi/DecisionTree.jl.svg?branch=master)](https://travis-ci.org/bensadeghi/DecisionTree.jl)
44
[![Coverage Status](https://coveralls.io/repos/bensadeghi/DecisionTree.jl/badge.svg?branch=master)](https://coveralls.io/r/bensadeghi/DecisionTree.jl?branch=master)
5-
6-
[![DecisionTree](http://pkg.julialang.org/badges/DecisionTree_0.5.svg)](http://pkg.julialang.org/?pkg=DecisionTree&ver=0.5)
7-
[![DecisionTree](http://pkg.julialang.org/badges/DecisionTree_0.6.svg)](http://pkg.julialang.org/?pkg=DecisionTree&ver=0.6)
8-
[![DecisionTree](http://pkg.julialang.org/badges/DecisionTree_0.7.svg)](http://pkg.julialang.org/?pkg=DecisionTree&ver=0.7)
5+
[![Docs Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://pkg.julialang.org/docs/DecisionTree/pEDeB/0.8.1/)
96

107
Julia implementation of Decision Tree and Random Forest algorithms
118

src/classification/main.jl

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -342,71 +342,3 @@ function apply_adaboost_stumps_proba(stumps::Ensemble{S, T}, coeffs::Vector{Floa
342342
features::Matrix{S}, labels::Vector{T}) where {S, T}
343343
stack_function_results(row->apply_adaboost_stumps_proba(stumps, coeffs, row, labels), features)
344344
end
345-
346-
347-
#= temporarily commenting out new prune_tree implementation
348-
function prune_tree(tree::LeafOrNode{S, T}, purity_thresh=0.0) where {S, T}
349-
350-
function recursive_assign(leaf::Leaf{T}, set::Set{T})
351-
for item in leaf.values
352-
push!(set, item)
353-
end
354-
end
355-
356-
function recursive_assign(node::Node{S, T}, set::Set{T})
357-
recursive_assign(node.left, set)
358-
recursive_assign(node.right, set)
359-
end
360-
361-
function recurse(
362-
leaf :: Leaf{T},
363-
purity_thresh :: Float64,
364-
label2int :: Dict{T, Int},
365-
labels :: Vector{T})
366-
nc = fill(0.0, length(labels))
367-
for i in leaf.values
368-
nc[label2int[i]] += 1.0
369-
end
370-
return nc, leaf
371-
end
372-
373-
function recurse(
374-
node :: Node{S, T},
375-
purity_thresh :: Float64,
376-
label2int :: Dict{T, Int},
377-
labels :: Vector{T})
378-
379-
ncl, l = recurse(node.left, purity_thresh, label2int, labels)
380-
ncr, r = recurse(node.right, purity_thresh, label2int, labels)
381-
382-
if is_leaf(l) && is_leaf(r)
383-
384-
@simd for i in 1:length(labels)
385-
ncl[i] += ncr[i]
386-
end
387-
388-
n_samples = length(l.values) + length(r.values)
389-
purity = -util.entropy(ncl, n_samples)
390-
if purity > purity_thresh
391-
return ncl, Leaf{T}(labels[argmax(ncl)], [l.values; r.values])
392-
end
393-
394-
end
395-
396-
return ncl, Node{S, T}(node.featid, node.featval, l, r)
397-
end
398-
399-
function main(tree::LeafOrNode{S, T}, purity_thresh=1.0)
400-
set = Set{T}()
401-
recursive_assign(tree, set)
402-
labels = collect(set)
403-
label2int = Dict{T, Int}(label=>i for (i, label) in enumerate(labels))
404-
405-
ncl, node = recurse(tree, purity_thresh, label2int, labels)
406-
407-
return node
408-
end
409-
410-
return main(tree, purity_thresh)
411-
end
412-
=#

src/regression/main.jl

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -93,43 +93,3 @@ function build_forest(
9393
return Ensemble{S, T}(forest)
9494
end
9595
end
96-
97-
98-
#= temporarily commenting out new prune_tree implementation
99-
function prune_tree(tree::LeafOrNode{S, T}, purity_thresh=0.0) where {S, T <: Float64}
100-
101-
function recurse(leaf :: Leaf{T}, purity_thresh :: Float64)
102-
tssq = 0.0
103-
tsum = 0.0
104-
for v in leaf.values
105-
tssq += v*v
106-
tsum += v
107-
end
108-
109-
return tssq, tsum, leaf
110-
end
111-
112-
function recurse(node :: Node{S, T}, purity_thresh :: Float64)
113-
114-
lssq, lsum, l = recurse(node.left, purity_thresh)
115-
rssq, rsum, r = recurse(node.right, purity_thresh)
116-
117-
if is_leaf(l) && is_leaf(r)
118-
n_samples = length(l.values) + length(r.values)
119-
tsum = lsum + rsum
120-
tssq = lssq + rssq
121-
tavg = tsum / n_samples
122-
purity = tavg * tavg - tssq / n_samples
123-
if purity > purity_thresh
124-
return tsum, tssq, Leaf{T}(tavg, [l.values; r.values])
125-
end
126-
127-
end
128-
129-
return 0.0, 0.0, Node{S, T}(node.featid, node.featval, l, r)
130-
end
131-
132-
_, _, node = recurse(tree, purity_thresh)
133-
return node
134-
end
135-
=#

test/local_runtests.jl

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/runtests.jl

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,56 @@
11
using DecisionTree
2+
using DelimitedFiles
3+
using Distributed
4+
using Random
5+
using ScikitLearnBase
6+
using Statistics
7+
using Test
28

3-
include("test_suites.jl")
9+
println("Julia version: ", VERSION)
10+
11+
function run_tests(list)
12+
for test in list
13+
println("TEST: $test \n")
14+
include(test)
15+
println("=" ^ 50)
16+
end
17+
end
18+
19+
classification = [
20+
"classification/random.jl",
21+
"classification/low_precision.jl",
22+
"classification/heterogeneous.jl",
23+
"classification/digits.jl",
24+
"classification/iris.jl",
25+
"classification/adult.jl",
26+
"classification/scikitlearn.jl"
27+
]
28+
29+
regression = [
30+
"regression/random.jl",
31+
"regression/low_precision.jl",
32+
"regression/digits.jl",
33+
"regression/scikitlearn.jl"
34+
]
35+
36+
miscellaneous = [
37+
"miscellaneous/parallel.jl"
38+
]
39+
40+
test_suites = [
41+
("Classification", classification),
42+
("Regression", regression),
43+
("Miscellaneous", miscellaneous),
44+
]
45+
46+
@testset "Test Suites" begin
47+
for ts in 1:length(test_suites)
48+
name = test_suites[ts][1]
49+
list = test_suites[ts][2]
50+
let
51+
@testset "$name" begin
52+
run_tests(list)
53+
end
54+
end
55+
end
56+
end

test/test_suites.jl

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)