Refactored decision trees and forests to support CART algorithm.
Notable changes:
1) Supports classification and regression
2) 3 classification criteria, 1 regression criterion
3) A new dataset is provided to test regression (Boston House Prices)
4) Weights are removed from the algorithm entirely. If the need for weights can be justified, I would welcome reintroducing them, but for the refactoring I left them out.
5) The subset of dimensions (F) to split on is fixed for the entire tree, not at each node. This is more in line with CART and RandomForests.
6) A max_depth parameter is offered to limit the size of the constructed trees.
7) Randomisation is fixed with python's random module, but can be seeded.
8) For classification, the number of classes must be provided when the tree is constructed. This is because the tree cannot necessarily infer the correct number of labels at the time of training if only a subset of the data is used for individual trees.
9) For classification, labels are not normalised internally. Labels must be provided to the algorithm in the range [0, ..., K)
10) For classification, the leaf nodes retain the distribution of classes. This means that it is possible to query the tree for the probability distribution of a test sample
2011-07-29 19:20:03 +08:00
|
|
|
"""
|
|
|
|
|
To run this, you'll need to have installed.
|
|
|
|
|
|
2011-09-04 16:54:21 +08:00
|
|
|
* scikit-learn
|
Refactored decision trees and forests to support CART algorithm.
Notable changes:
1) Supports classification and regression
2) 3 classification criteria, 1 regression criterion
3) A new dataset is provided to test regression (Boston House Prices)
4) Weights are removed from the algorithm entirely. If the need for weights can be justified, I would welcome reintroducing them, but for the refactoring I left them out.
5) The subset of dimensions (F) to split on is fixed for the entire tree, not at each node. This is more in line with CART and RandomForests.
6) A max_depth parameter is offered to limit the size of the constructed trees.
7) Randomisation is fixed with python's random module, but can be seeded.
8) For classification, the number of classes must be provided when the tree is constructed. This is because the tree cannot necessarily infer the correct number of labels at the time of training if only a subset of the data is used for individual trees.
9) For classification, labels are not normalised internally. Labels must be provided to the algorithm in the range [0, ..., K)
10) For classification, the leaf nodes retain the distribution of classes. This means that it is possible to query the tree for the probability distribution of a test sample
2011-07-29 19:20:03 +08:00
|
|
|
|
|
|
|
|
Does two benchmarks
|
|
|
|
|
|
|
|
|
|
First, we fix a training set, increase the number of
|
|
|
|
|
samples to classify and plot number of classified samples as a
|
|
|
|
|
function of time.
|
|
|
|
|
|
|
|
|
|
In the second benchmark, we increase the number of dimensions of the
|
|
|
|
|
training set, classify a sample and plot the time taken as a function
|
|
|
|
|
of the number of dimensions.
|
|
|
|
|
"""
|
|
|
|
|
import numpy as np
|
[MRG+1] Fix: Replace pylab with matplotlib.pyplot #6754 (#6762)
* Fix: Replace pylab with matplotlib.pyplot #6754
- one instance of 22 occurrences of pylab replaced with matplotlib.pyplot
- bench_glm.py now free of pylab references
- code executes properly
* Fix: Replace pylab with matplotlib.pyplot #6754
- one instance of 21 remaining occurrences of pylab replaced with
matplotlib.pyplot
- bench_glmnet.py now free of pylab references
- code does not execute for extraneous reason: ImportError: No module named
glmnet.elastic_net
* Fix: Replace pylab with matplotlib.pyplot #6754
- one instance of 19 occurrences of pylab replaced with matplotlib.pyplot
- bench_lasso.py now free of pylab references
- code executes properly
* Fix: Replace pylab with matplotlib.pyplot #6754
- one instance of 18 occurrences of pylab replaced with matplotlib.pyplot
- bench_plot_neighbors.py now free of pylab references
- code executes properly
* Fix: Replace pylab with matplotlib.pyplot #6754
- one instance of 17 occurrences of pylab replaced with matplotlib.pyplot
- bench_plot_omp_lars.py now free of pylab references
- code does not execute for extraneous reasons:
- File "bench_plot_omp_lars.py", line 111, in <module>
- ax = fig.add_subplot(1, 2, i)
- ValueError: num must be 1 <= num <= 2, not 0
- line 111 should probably be ax = fig.add_subplot(1, 2, i+1)
* Fix: Replace pylab with matplotlib.pyplot #6754
- bench_plot_parallel_pairwise.py now free of pylab references
- code executes properly
* Fix: Replace pylab with matplotlib.pyplot #6754
- bench_plot_ward.py now free of pylab references
- code executes properly
* Fix: Replace pylab with matplotlib.pyplot #6754
- bench_sgd_regression.py now free of pylab references
- code executes properly
* Fix: Replace pylab with matplotlib.pyplot #6754
- bench_tree.py now free of pylab references
- code executes properly
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- bench_glm.py clean
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- bench_glm.py clean of pl
- code does not execute for extraneous reasons
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- bench_lasso.py clean of pl
- code executes properly
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- bench_plot_neighbors.py clean of pl
- code executes properly
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- bench_plot_omp_lars.py clean of pl
- code does not execute for extraneous reasons
* fix: Fix bug that prevented graphs from displaying
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- bench_plot_parallel_pairwise.py clean of pl
- code executes properly
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- bench_plot_ward.py clean of pl
- code executes properly
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- bench_sgd_regression.py clean of pl
- code executes properly
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- bench_tree.py clean of pl
- code executes properly
* docs: removed pylab references from comments
* docs: removed all pylab references
- replaced with matplotlib.pyplot
- pl --> plt
* docs: removed pylab references from comments
- replaced with matplotlib.pyplot
- pl --> plt
* docs: removed all pylab references
- replaced with matplotlib.pyplot
- pl --> plt
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- mlcomp_sparse_document_classification.py clean of pl
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- plot_gpr_noisy_targets.py clean of pl
- code does not execute for extraneous reasons
- File "examples/gaussian_process/plot_gpr_noisy_targets.py", line 31, in
<module>
- from sklearn.gaussian_process import GaussianProcessRegressor
- ImportError: cannot import name GaussianProcessRegressor
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- plot_gpc_isoprobability.py clean of pl
- code does not execute for extraneous reasons
- File "examples/gaussian_process/plot_gpc_isoprobability.py", line 24, in
<module>
- from sklearn.gaussian_process import GaussianProcessClassifier
- ImportError: cannot import name GaussianProcessClassifier
* docs: removed all pylab references
- replaced with matplotlib.pyplot
- pl --> plt
* docs: removed all pylab references
- replaced with matplotlib.pyplot
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- plot_sparse_coding.py clean of pl
- code executes properly
* docs: removed all pylab references
- replaced with matplotlib.pyplot
* docs: removed all pylab references
- replaced with matplotlib.pyplot
* style: Indent properly
* style: indent properly
* style: Indent properly
* docs: Add missing .pyplot
* docs: Fix typo
* style: Indent properly
2016-05-10 17:34:33 +08:00
|
|
|
import matplotlib.pyplot as plt
|
Refactored decision trees and forests to support CART algorithm.
Notable changes:
1) Supports classification and regression
2) 3 classification criteria, 1 regression criterion
3) A new dataset is provided to test regression (Boston House Prices)
4) Weights are removed from the algorithm entirely. If the need for weights can be justified, I would welcome reintroducing them, but for the refactoring I left them out.
5) The subset of dimensions (F) to split on is fixed for the entire tree, not at each node. This is more in line with CART and RandomForests.
6) A max_depth parameter is offered to limit the size of the constructed trees.
7) Randomisation is fixed with python's random module, but can be seeded.
8) For classification, the number of classes must be provided when the tree is constructed. This is because the tree cannot necessarily infer the correct number of labels at the time of training if only a subset of the data is used for individual trees.
9) For classification, labels are not normalised internally. Labels must be provided to the algorithm in the range [0, ..., K)
10) For classification, the leaf nodes retain the distribution of classes. This means that it is possible to query the tree for the probability distribution of a test sample
2011-07-29 19:20:03 +08:00
|
|
|
import gc
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
# to store the results
|
|
|
|
|
scikit_classifier_results = []
|
|
|
|
|
scikit_regressor_results = []
|
|
|
|
|
|
2011-09-04 16:54:21 +08:00
|
|
|
mu_second = 0.0 + 10**6 # number of microseconds in a second
|
Refactored decision trees and forests to support CART algorithm.
Notable changes:
1) Supports classification and regression
2) 3 classification criteria, 1 regression criterion
3) A new dataset is provided to test regression (Boston House Prices)
4) Weights are removed from the algorithm entirely. If the need for weights can be justified, I would welcome reintroducing them, but for the refactoring I left them out.
5) The subset of dimensions (F) to split on is fixed for the entire tree, not at each node. This is more in line with CART and RandomForests.
6) A max_depth parameter is offered to limit the size of the constructed trees.
7) Randomisation is fixed with python's random module, but can be seeded.
8) For classification, the number of classes must be provided when the tree is constructed. This is because the tree cannot necessarily infer the correct number of labels at the time of training if only a subset of the data is used for individual trees.
9) For classification, labels are not normalised internally. Labels must be provided to the algorithm in the range [0, ..., K)
10) For classification, the leaf nodes retain the distribution of classes. This means that it is possible to query the tree for the probability distribution of a test sample
2011-07-29 19:20:03 +08:00
|
|
|
|
|
|
|
|
|
2011-08-09 19:45:53 +08:00
|
|
|
def bench_scikit_tree_classifier(X, Y):
|
2013-05-28 14:27:20 +08:00
|
|
|
"""Benchmark with scikit-learn decision tree classifier"""
|
2011-09-03 17:35:07 +08:00
|
|
|
|
2011-09-03 20:04:27 +08:00
|
|
|
from sklearn.tree import DecisionTreeClassifier
|
Refactored decision trees and forests to support CART algorithm.
Notable changes:
1) Supports classification and regression
2) 3 classification criteria, 1 regression criterion
3) A new dataset is provided to test regression (Boston House Prices)
4) Weights are removed from the algorithm entirely. If the need for weights can be justified, I would welcome reintroducing them, but for the refactoring I left them out.
5) The subset of dimensions (F) to split on is fixed for the entire tree, not at each node. This is more in line with CART and RandomForests.
6) A max_depth parameter is offered to limit the size of the constructed trees.
7) Randomisation is fixed with python's random module, but can be seeded.
8) For classification, the number of classes must be provided when the tree is constructed. This is because the tree cannot necessarily infer the correct number of labels at the time of training if only a subset of the data is used for individual trees.
9) For classification, labels are not normalised internally. Labels must be provided to the algorithm in the range [0, ..., K)
10) For classification, the leaf nodes retain the distribution of classes. This means that it is possible to query the tree for the probability distribution of a test sample
2011-07-29 19:20:03 +08:00
|
|
|
|
|
|
|
|
gc.collect()
|
|
|
|
|
|
|
|
|
|
# start time
|
|
|
|
|
tstart = datetime.now()
|
2011-08-09 19:45:53 +08:00
|
|
|
clf = DecisionTreeClassifier()
|
Refactored decision trees and forests to support CART algorithm.
Notable changes:
1) Supports classification and regression
2) 3 classification criteria, 1 regression criterion
3) A new dataset is provided to test regression (Boston House Prices)
4) Weights are removed from the algorithm entirely. If the need for weights can be justified, I would welcome reintroducing them, but for the refactoring I left them out.
5) The subset of dimensions (F) to split on is fixed for the entire tree, not at each node. This is more in line with CART and RandomForests.
6) A max_depth parameter is offered to limit the size of the constructed trees.
7) Randomisation is fixed with python's random module, but can be seeded.
8) For classification, the number of classes must be provided when the tree is constructed. This is because the tree cannot necessarily infer the correct number of labels at the time of training if only a subset of the data is used for individual trees.
9) For classification, labels are not normalised internally. Labels must be provided to the algorithm in the range [0, ..., K)
10) For classification, the leaf nodes retain the distribution of classes. This means that it is possible to query the tree for the probability distribution of a test sample
2011-07-29 19:20:03 +08:00
|
|
|
clf.fit(X, Y).predict(X)
|
|
|
|
|
delta = datetime.now() - tstart
|
|
|
|
|
# stop time
|
|
|
|
|
|
2011-09-04 16:54:21 +08:00
|
|
|
scikit_classifier_results.append(delta.seconds + delta.microseconds / mu_second)
|
|
|
|
|
|
Refactored decision trees and forests to support CART algorithm.
Notable changes:
1) Supports classification and regression
2) 3 classification criteria, 1 regression criterion
3) A new dataset is provided to test regression (Boston House Prices)
4) Weights are removed from the algorithm entirely. If the need for weights can be justified, I would welcome reintroducing them, but for the refactoring I left them out.
5) The subset of dimensions (F) to split on is fixed for the entire tree, not at each node. This is more in line with CART and RandomForests.
6) A max_depth parameter is offered to limit the size of the constructed trees.
7) Randomisation is fixed with python's random module, but can be seeded.
8) For classification, the number of classes must be provided when the tree is constructed. This is because the tree cannot necessarily infer the correct number of labels at the time of training if only a subset of the data is used for individual trees.
9) For classification, labels are not normalised internally. Labels must be provided to the algorithm in the range [0, ..., K)
10) For classification, the leaf nodes retain the distribution of classes. This means that it is possible to query the tree for the probability distribution of a test sample
2011-07-29 19:20:03 +08:00
|
|
|
|
|
|
|
|
def bench_scikit_tree_regressor(X, Y):
|
2013-05-28 14:27:20 +08:00
|
|
|
"""Benchmark with scikit-learn decision tree regressor"""
|
2011-09-03 17:35:07 +08:00
|
|
|
|
2011-09-04 02:58:20 +08:00
|
|
|
from sklearn.tree import DecisionTreeRegressor
|
Refactored decision trees and forests to support CART algorithm.
Notable changes:
1) Supports classification and regression
2) 3 classification criteria, 1 regression criterion
3) A new dataset is provided to test regression (Boston House Prices)
4) Weights are removed from the algorithm entirely. If the need for weights can be justified, I would welcome reintroducing them, but for the refactoring I left them out.
5) The subset of dimensions (F) to split on is fixed for the entire tree, not at each node. This is more in line with CART and RandomForests.
6) A max_depth parameter is offered to limit the size of the constructed trees.
7) Randomisation is fixed with python's random module, but can be seeded.
8) For classification, the number of classes must be provided when the tree is constructed. This is because the tree cannot necessarily infer the correct number of labels at the time of training if only a subset of the data is used for individual trees.
9) For classification, labels are not normalised internally. Labels must be provided to the algorithm in the range [0, ..., K)
10) For classification, the leaf nodes retain the distribution of classes. This means that it is possible to query the tree for the probability distribution of a test sample
2011-07-29 19:20:03 +08:00
|
|
|
|
|
|
|
|
gc.collect()
|
|
|
|
|
|
|
|
|
|
# start time
|
|
|
|
|
tstart = datetime.now()
|
|
|
|
|
clf = DecisionTreeRegressor()
|
|
|
|
|
clf.fit(X, Y).predict(X)
|
|
|
|
|
delta = datetime.now() - tstart
|
|
|
|
|
# stop time
|
|
|
|
|
|
2011-09-04 16:54:21 +08:00
|
|
|
scikit_regressor_results.append(delta.seconds + delta.microseconds / mu_second)
|
|
|
|
|
|
Refactored decision trees and forests to support CART algorithm.
Notable changes:
1) Supports classification and regression
2) 3 classification criteria, 1 regression criterion
3) A new dataset is provided to test regression (Boston House Prices)
4) Weights are removed from the algorithm entirely. If the need for weights can be justified, I would welcome reintroducing them, but for the refactoring I left them out.
5) The subset of dimensions (F) to split on is fixed for the entire tree, not at each node. This is more in line with CART and RandomForests.
6) A max_depth parameter is offered to limit the size of the constructed trees.
7) Randomisation is fixed with python's random module, but can be seeded.
8) For classification, the number of classes must be provided when the tree is constructed. This is because the tree cannot necessarily infer the correct number of labels at the time of training if only a subset of the data is used for individual trees.
9) For classification, labels are not normalised internally. Labels must be provided to the algorithm in the range [0, ..., K)
10) For classification, the leaf nodes retain the distribution of classes. This means that it is possible to query the tree for the probability distribution of a test sample
2011-07-29 19:20:03 +08:00
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
|
2013-02-12 06:11:57 +08:00
|
|
|
print("============================================")
|
|
|
|
|
print("Warning: this is going to take a looong time")
|
|
|
|
|
print("============================================")
|
2011-08-09 19:45:53 +08:00
|
|
|
|
Refactored decision trees and forests to support CART algorithm.
Notable changes:
1) Supports classification and regression
2) 3 classification criteria, 1 regression criterion
3) A new dataset is provided to test regression (Boston House Prices)
4) Weights are removed from the algorithm entirely. If the need for weights can be justified, I would welcome reintroducing them, but for the refactoring I left them out.
5) The subset of dimensions (F) to split on is fixed for the entire tree, not at each node. This is more in line with CART and RandomForests.
6) A max_depth parameter is offered to limit the size of the constructed trees.
7) Randomisation is fixed with python's random module, but can be seeded.
8) For classification, the number of classes must be provided when the tree is constructed. This is because the tree cannot necessarily infer the correct number of labels at the time of training if only a subset of the data is used for individual trees.
9) For classification, labels are not normalised internally. Labels must be provided to the algorithm in the range [0, ..., K)
10) For classification, the leaf nodes retain the distribution of classes. This means that it is possible to query the tree for the probability distribution of a test sample
2011-07-29 19:20:03 +08:00
|
|
|
n = 10
|
2011-08-09 19:45:53 +08:00
|
|
|
step = 10000
|
|
|
|
|
n_samples = 10000
|
Refactored decision trees and forests to support CART algorithm.
Notable changes:
1) Supports classification and regression
2) 3 classification criteria, 1 regression criterion
3) A new dataset is provided to test regression (Boston House Prices)
4) Weights are removed from the algorithm entirely. If the need for weights can be justified, I would welcome reintroducing them, but for the refactoring I left them out.
5) The subset of dimensions (F) to split on is fixed for the entire tree, not at each node. This is more in line with CART and RandomForests.
6) A max_depth parameter is offered to limit the size of the constructed trees.
7) Randomisation is fixed with python's random module, but can be seeded.
8) For classification, the number of classes must be provided when the tree is constructed. This is because the tree cannot necessarily infer the correct number of labels at the time of training if only a subset of the data is used for individual trees.
9) For classification, labels are not normalised internally. Labels must be provided to the algorithm in the range [0, ..., K)
10) For classification, the leaf nodes retain the distribution of classes. This means that it is possible to query the tree for the probability distribution of a test sample
2011-07-29 19:20:03 +08:00
|
|
|
dim = 10
|
2011-09-04 16:54:21 +08:00
|
|
|
n_classes = 10
|
Refactored decision trees and forests to support CART algorithm.
Notable changes:
1) Supports classification and regression
2) 3 classification criteria, 1 regression criterion
3) A new dataset is provided to test regression (Boston House Prices)
4) Weights are removed from the algorithm entirely. If the need for weights can be justified, I would welcome reintroducing them, but for the refactoring I left them out.
5) The subset of dimensions (F) to split on is fixed for the entire tree, not at each node. This is more in line with CART and RandomForests.
6) A max_depth parameter is offered to limit the size of the constructed trees.
7) Randomisation is fixed with python's random module, but can be seeded.
8) For classification, the number of classes must be provided when the tree is constructed. This is because the tree cannot necessarily infer the correct number of labels at the time of training if only a subset of the data is used for individual trees.
9) For classification, labels are not normalised internally. Labels must be provided to the algorithm in the range [0, ..., K)
10) For classification, the leaf nodes retain the distribution of classes. This means that it is possible to query the tree for the probability distribution of a test sample
2011-07-29 19:20:03 +08:00
|
|
|
for i in range(n):
|
2013-02-12 06:11:57 +08:00
|
|
|
print("============================================")
|
|
|
|
|
print("Entering iteration %s of %s" % (i, n))
|
|
|
|
|
print("============================================")
|
Refactored decision trees and forests to support CART algorithm.
Notable changes:
1) Supports classification and regression
2) 3 classification criteria, 1 regression criterion
3) A new dataset is provided to test regression (Boston House Prices)
4) Weights are removed from the algorithm entirely. If the need for weights can be justified, I would welcome reintroducing them, but for the refactoring I left them out.
5) The subset of dimensions (F) to split on is fixed for the entire tree, not at each node. This is more in line with CART and RandomForests.
6) A max_depth parameter is offered to limit the size of the constructed trees.
7) Randomisation is fixed with python's random module, but can be seeded.
8) For classification, the number of classes must be provided when the tree is constructed. This is because the tree cannot necessarily infer the correct number of labels at the time of training if only a subset of the data is used for individual trees.
9) For classification, labels are not normalised internally. Labels must be provided to the algorithm in the range [0, ..., K)
10) For classification, the leaf nodes retain the distribution of classes. This means that it is possible to query the tree for the probability distribution of a test sample
2011-07-29 19:20:03 +08:00
|
|
|
n_samples += step
|
|
|
|
|
X = np.random.randn(n_samples, dim)
|
2011-09-03 17:35:07 +08:00
|
|
|
Y = np.random.randint(0, n_classes, (n_samples,))
|
2011-08-09 19:45:53 +08:00
|
|
|
bench_scikit_tree_classifier(X, Y)
|
Refactored decision trees and forests to support CART algorithm.
Notable changes:
1) Supports classification and regression
2) 3 classification criteria, 1 regression criterion
3) A new dataset is provided to test regression (Boston House Prices)
4) Weights are removed from the algorithm entirely. If the need for weights can be justified, I would welcome reintroducing them, but for the refactoring I left them out.
5) The subset of dimensions (F) to split on is fixed for the entire tree, not at each node. This is more in line with CART and RandomForests.
6) A max_depth parameter is offered to limit the size of the constructed trees.
7) Randomisation is fixed with python's random module, but can be seeded.
8) For classification, the number of classes must be provided when the tree is constructed. This is because the tree cannot necessarily infer the correct number of labels at the time of training if only a subset of the data is used for individual trees.
9) For classification, labels are not normalised internally. Labels must be provided to the algorithm in the range [0, ..., K)
10) For classification, the leaf nodes retain the distribution of classes. This means that it is possible to query the tree for the probability distribution of a test sample
2011-07-29 19:20:03 +08:00
|
|
|
Y = np.random.randn(n_samples)
|
|
|
|
|
bench_scikit_tree_regressor(X, Y)
|
|
|
|
|
|
2011-09-04 16:54:21 +08:00
|
|
|
xx = range(0, n * step, step)
|
[MRG+1] Fix: Replace pylab with matplotlib.pyplot #6754 (#6762)
* Fix: Replace pylab with matplotlib.pyplot #6754
- one instance of 22 occurrences of pylab replaced with matplotlib.pyplot
- bench_glm.py now free of pylab references
- code executes properly
* Fix: Replace pylab with matplotlib.pyplot #6754
- one instance of 21 remaining occurrences of pylab replaced with
matplotlib.pyplot
- bench_glmnet.py now free of pylab references
- code does not execute for extraneous reason: ImportError: No module named
glmnet.elastic_net
* Fix: Replace pylab with matplotlib.pyplot #6754
- one instance of 19 occurrences of pylab replaced with matplotlib.pyplot
- bench_lasso.py now free of pylab references
- code executes properly
* Fix: Replace pylab with matplotlib.pyplot #6754
- one instance of 18 occurrences of pylab replaced with matplotlib.pyplot
- bench_plot_neighbors.py now free of pylab references
- code executes properly
* Fix: Replace pylab with matplotlib.pyplot #6754
- one instance of 17 occurrences of pylab replaced with matplotlib.pyplot
- bench_plot_omp_lars.py now free of pylab references
- code does not execute for extraneous reasons:
- File "bench_plot_omp_lars.py", line 111, in <module>
- ax = fig.add_subplot(1, 2, i)
- ValueError: num must be 1 <= num <= 2, not 0
- line 111 should probably be ax = fig.add_subplot(1, 2, i+1)
* Fix: Replace pylab with matplotlib.pyplot #6754
- bench_plot_parallel_pairwise.py now free of pylab references
- code executes properly
* Fix: Replace pylab with matplotlib.pyplot #6754
- bench_plot_ward.py now free of pylab references
- code executes properly
* Fix: Replace pylab with matplotlib.pyplot #6754
- bench_sgd_regression.py now free of pylab references
- code executes properly
* Fix: Replace pylab with matplotlib.pyplot #6754
- bench_tree.py now free of pylab references
- code executes properly
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- bench_glm.py clean
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- bench_glm.py clean of pl
- code does not execute for extraneous reasons
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- bench_lasso.py clean of pl
- code executes properly
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- bench_plot_neighbors.py clean of pl
- code executes properly
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- bench_plot_omp_lars.py clean of pl
- code does not execute for extraneous reasons
* fix: Fix bug that prevented graphs from displaying
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- bench_plot_parallel_pairwise.py clean of pl
- code executes properly
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- bench_plot_ward.py clean of pl
- code executes properly
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- bench_sgd_regression.py clean of pl
- code executes properly
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- bench_tree.py clean of pl
- code executes properly
* docs: removed pylab references from comments
* docs: removed all pylab references
- replaced with matplotlib.pyplot
- pl --> plt
* docs: removed pylab references from comments
- replaced with matplotlib.pyplot
- pl --> plt
* docs: removed all pylab references
- replaced with matplotlib.pyplot
- pl --> plt
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- mlcomp_sparse_document_classification.py clean of pl
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- plot_gpr_noisy_targets.py clean of pl
- code does not execute for extraneous reasons
- File "examples/gaussian_process/plot_gpr_noisy_targets.py", line 31, in
<module>
- from sklearn.gaussian_process import GaussianProcessRegressor
- ImportError: cannot import name GaussianProcessRegressor
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- plot_gpc_isoprobability.py clean of pl
- code does not execute for extraneous reasons
- File "examples/gaussian_process/plot_gpc_isoprobability.py", line 24, in
<module>
- from sklearn.gaussian_process import GaussianProcessClassifier
- ImportError: cannot import name GaussianProcessClassifier
* docs: removed all pylab references
- replaced with matplotlib.pyplot
- pl --> plt
* docs: removed all pylab references
- replaced with matplotlib.pyplot
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- plot_sparse_coding.py clean of pl
- code executes properly
* docs: removed all pylab references
- replaced with matplotlib.pyplot
* docs: removed all pylab references
- replaced with matplotlib.pyplot
* style: Indent properly
* style: indent properly
* style: Indent properly
* docs: Add missing .pyplot
* docs: Fix typo
* style: Indent properly
2016-05-10 17:34:33 +08:00
|
|
|
plt.figure("scikit-learn tree benchmark results")
|
|
|
|
|
plt.subplot(211)
|
|
|
|
|
plt.title("Learning with varying number of samples")
|
|
|
|
|
plt.plot(xx, scikit_classifier_results, "g-", label="classification")
|
|
|
|
|
plt.plot(xx, scikit_regressor_results, "r-", label="regression")
|
|
|
|
|
plt.legend(loc="upper left")
|
|
|
|
|
plt.xlabel("number of samples")
|
|
|
|
|
plt.ylabel("Time (s)")
|
Refactored decision trees and forests to support CART algorithm.
Notable changes:
1) Supports classification and regression
2) 3 classification criteria, 1 regression criterion
3) A new dataset is provided to test regression (Boston House Prices)
4) Weights are removed from the algorithm entirely. If the need for weights can be justified, I would welcome reintroducing them, but for the refactoring I left them out.
5) The subset of dimensions (F) to split on is fixed for the entire tree, not at each node. This is more in line with CART and RandomForests.
6) A max_depth parameter is offered to limit the size of the constructed trees.
7) Randomisation is fixed with python's random module, but can be seeded.
8) For classification, the number of classes must be provided when the tree is constructed. This is because the tree cannot necessarily infer the correct number of labels at the time of training if only a subset of the data is used for individual trees.
9) For classification, labels are not normalised internally. Labels must be provided to the algorithm in the range [0, ..., K)
10) For classification, the leaf nodes retain the distribution of classes. This means that it is possible to query the tree for the probability distribution of a test sample
2011-07-29 19:20:03 +08:00
|
|
|
|
|
|
|
|
scikit_classifier_results = []
|
|
|
|
|
scikit_regressor_results = []
|
|
|
|
|
n = 10
|
2011-08-09 19:45:53 +08:00
|
|
|
step = 500
|
|
|
|
|
start_dim = 500
|
2011-09-04 16:54:21 +08:00
|
|
|
n_classes = 10
|
Refactored decision trees and forests to support CART algorithm.
Notable changes:
1) Supports classification and regression
2) 3 classification criteria, 1 regression criterion
3) A new dataset is provided to test regression (Boston House Prices)
4) Weights are removed from the algorithm entirely. If the need for weights can be justified, I would welcome reintroducing them, but for the refactoring I left them out.
5) The subset of dimensions (F) to split on is fixed for the entire tree, not at each node. This is more in line with CART and RandomForests.
6) A max_depth parameter is offered to limit the size of the constructed trees.
7) Randomisation is fixed with python's random module, but can be seeded.
8) For classification, the number of classes must be provided when the tree is constructed. This is because the tree cannot necessarily infer the correct number of labels at the time of training if only a subset of the data is used for individual trees.
9) For classification, labels are not normalised internally. Labels must be provided to the algorithm in the range [0, ..., K)
10) For classification, the leaf nodes retain the distribution of classes. This means that it is possible to query the tree for the probability distribution of a test sample
2011-07-29 19:20:03 +08:00
|
|
|
|
|
|
|
|
dim = start_dim
|
|
|
|
|
for i in range(0, n):
|
2013-02-12 06:11:57 +08:00
|
|
|
print("============================================")
|
|
|
|
|
print("Entering iteration %s of %s" % (i, n))
|
|
|
|
|
print("============================================")
|
Refactored decision trees and forests to support CART algorithm.
Notable changes:
1) Supports classification and regression
2) 3 classification criteria, 1 regression criterion
3) A new dataset is provided to test regression (Boston House Prices)
4) Weights are removed from the algorithm entirely. If the need for weights can be justified, I would welcome reintroducing them, but for the refactoring I left them out.
5) The subset of dimensions (F) to split on is fixed for the entire tree, not at each node. This is more in line with CART and RandomForests.
6) A max_depth parameter is offered to limit the size of the constructed trees.
7) Randomisation is fixed with python's random module, but can be seeded.
8) For classification, the number of classes must be provided when the tree is constructed. This is because the tree cannot necessarily infer the correct number of labels at the time of training if only a subset of the data is used for individual trees.
9) For classification, labels are not normalised internally. Labels must be provided to the algorithm in the range [0, ..., K)
10) For classification, the leaf nodes retain the distribution of classes. This means that it is possible to query the tree for the probability distribution of a test sample
2011-07-29 19:20:03 +08:00
|
|
|
dim += step
|
|
|
|
|
X = np.random.randn(100, dim)
|
2011-09-03 17:35:07 +08:00
|
|
|
Y = np.random.randint(0, n_classes, (100,))
|
2011-08-09 19:45:53 +08:00
|
|
|
bench_scikit_tree_classifier(X, Y)
|
Refactored decision trees and forests to support CART algorithm.
Notable changes:
1) Supports classification and regression
2) 3 classification criteria, 1 regression criterion
3) A new dataset is provided to test regression (Boston House Prices)
4) Weights are removed from the algorithm entirely. If the need for weights can be justified, I would welcome reintroducing them, but for the refactoring I left them out.
5) The subset of dimensions (F) to split on is fixed for the entire tree, not at each node. This is more in line with CART and RandomForests.
6) A max_depth parameter is offered to limit the size of the constructed trees.
7) Randomisation is fixed with python's random module, but can be seeded.
8) For classification, the number of classes must be provided when the tree is constructed. This is because the tree cannot necessarily infer the correct number of labels at the time of training if only a subset of the data is used for individual trees.
9) For classification, labels are not normalised internally. Labels must be provided to the algorithm in the range [0, ..., K)
10) For classification, the leaf nodes retain the distribution of classes. This means that it is possible to query the tree for the probability distribution of a test sample
2011-07-29 19:20:03 +08:00
|
|
|
Y = np.random.randn(100)
|
|
|
|
|
bench_scikit_tree_regressor(X, Y)
|
|
|
|
|
|
2011-09-04 16:54:21 +08:00
|
|
|
xx = np.arange(start_dim, start_dim + n * step, step)
|
[MRG+1] Fix: Replace pylab with matplotlib.pyplot #6754 (#6762)
* Fix: Replace pylab with matplotlib.pyplot #6754
- one instance of 22 occurrences of pylab replaced with matplotlib.pyplot
- bench_glm.py now free of pylab references
- code executes properly
* Fix: Replace pylab with matplotlib.pyplot #6754
- one instance of 21 remaining occurrences of pylab replaced with
matplotlib.pyplot
- bench_glmnet.py now free of pylab references
- code does not execute for extraneous reason: ImportError: No module named
glmnet.elastic_net
* Fix: Replace pylab with matplotlib.pyplot #6754
- one instance of 19 occurrences of pylab replaced with matplotlib.pyplot
- bench_lasso.py now free of pylab references
- code executes properly
* Fix: Replace pylab with matplotlib.pyplot #6754
- one instance of 18 occurrences of pylab replaced with matplotlib.pyplot
- bench_plot_neighbors.py now free of pylab references
- code executes properly
* Fix: Replace pylab with matplotlib.pyplot #6754
- one instance of 17 occurrences of pylab replaced with matplotlib.pyplot
- bench_plot_omp_lars.py now free of pylab references
- code does not execute for extraneous reasons:
- File "bench_plot_omp_lars.py", line 111, in <module>
- ax = fig.add_subplot(1, 2, i)
- ValueError: num must be 1 <= num <= 2, not 0
- line 111 should probably be ax = fig.add_subplot(1, 2, i+1)
* Fix: Replace pylab with matplotlib.pyplot #6754
- bench_plot_parallel_pairwise.py now free of pylab references
- code executes properly
* Fix: Replace pylab with matplotlib.pyplot #6754
- bench_plot_ward.py now free of pylab references
- code executes properly
* Fix: Replace pylab with matplotlib.pyplot #6754
- bench_sgd_regression.py now free of pylab references
- code executes properly
* Fix: Replace pylab with matplotlib.pyplot #6754
- bench_tree.py now free of pylab references
- code executes properly
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- bench_glm.py clean
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- bench_glm.py clean of pl
- code does not execute for extraneous reasons
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- bench_lasso.py clean of pl
- code executes properly
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- bench_plot_neighbors.py clean of pl
- code executes properly
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- bench_plot_omp_lars.py clean of pl
- code does not execute for extraneous reasons
* fix: Fix bug that prevented graphs from displaying
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- bench_plot_parallel_pairwise.py clean of pl
- code executes properly
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- bench_plot_ward.py clean of pl
- code executes properly
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- bench_sgd_regression.py clean of pl
- code executes properly
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- bench_tree.py clean of pl
- code executes properly
* docs: removed pylab references from comments
* docs: removed all pylab references
- replaced with matplotlib.pyplot
- pl --> plt
* docs: removed pylab references from comments
- replaced with matplotlib.pyplot
- pl --> plt
* docs: removed all pylab references
- replaced with matplotlib.pyplot
- pl --> plt
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- mlcomp_sparse_document_classification.py clean of pl
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- plot_gpr_noisy_targets.py clean of pl
- code does not execute for extraneous reasons
- File "examples/gaussian_process/plot_gpr_noisy_targets.py", line 31, in
<module>
- from sklearn.gaussian_process import GaussianProcessRegressor
- ImportError: cannot import name GaussianProcessRegressor
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- plot_gpc_isoprobability.py clean of pl
- code does not execute for extraneous reasons
- File "examples/gaussian_process/plot_gpc_isoprobability.py", line 24, in
<module>
- from sklearn.gaussian_process import GaussianProcessClassifier
- ImportError: cannot import name GaussianProcessClassifier
* docs: removed all pylab references
- replaced with matplotlib.pyplot
- pl --> plt
* docs: removed all pylab references
- replaced with matplotlib.pyplot
* refactor: Replace pl with plt
- replace instances of pl (as on import pylab as pl)
with plt (as in import matplotlib.pyplot as plt)
- plot_sparse_coding.py clean of pl
- code executes properly
* docs: removed all pylab references
- replaced with matplotlib.pyplot
* docs: removed all pylab references
- replaced with matplotlib.pyplot
* style: Indent properly
* style: indent properly
* style: Indent properly
* docs: Add missing .pyplot
* docs: Fix typo
* style: Indent properly
2016-05-10 17:34:33 +08:00
|
|
|
plt.subplot(212)
|
|
|
|
|
plt.title("Learning in high dimensional spaces")
|
|
|
|
|
plt.plot(xx, scikit_classifier_results, "g-", label="classification")
|
|
|
|
|
plt.plot(xx, scikit_regressor_results, "r-", label="regression")
|
|
|
|
|
plt.legend(loc="upper left")
|
|
|
|
|
plt.xlabel("number of dimensions")
|
|
|
|
|
plt.ylabel("Time (s)")
|
|
|
|
|
plt.axis("tight")
|
|
|
|
|
plt.show()
|