@@ -300,7 +300,7 @@ def test_xor():
300
300
clf .fit (X , y )
301
301
assert clf .score (X , y ) == 1.0 , "Failed with {0}" .format (name )
302
302
303
- clf = Tree (random_state = 0 , max_features = X . shape [ 1 ] )
303
+ clf = Tree (random_state = 0 , max_features = 1 )
304
304
clf .fit (X , y )
305
305
assert clf .score (X , y ) == 1.0 , "Failed with {0}" .format (name )
306
306
@@ -440,7 +440,7 @@ def test_importances():
440
440
X , y = datasets .make_classification (
441
441
n_samples = 5000 ,
442
442
n_features = 10 ,
443
- n_informative = 4 ,
443
+ n_informative = 3 ,
444
444
n_redundant = 0 ,
445
445
n_repeated = 0 ,
446
446
shuffle = False ,
@@ -455,7 +455,7 @@ def test_importances():
455
455
n_important = np .sum (importances > 0.1 )
456
456
457
457
assert importances .shape [0 ] == 10 , "Failed with {0}" .format (name )
458
- assert n_important == 4 , "Failed with {0}" .format (name )
458
+ assert n_important == 3 , "Failed with {0}" .format (name )
459
459
460
460
# Check on iris that importances are the same for all builders
461
461
clf = DecisionTreeClassifier (random_state = 0 )
@@ -466,9 +466,9 @@ def test_importances():
466
466
assert_array_equal (clf .feature_importances_ , clf2 .feature_importances_ )
467
467
468
468
469
- @pytest .mark .parametrize ("clf" , [DecisionTreeClassifier ()])
470
- def test_importances_raises (clf ):
469
+ def test_importances_raises ():
471
470
# Check if variable importance before fit raises ValueError.
471
+ clf = DecisionTreeClassifier ()
472
472
with pytest .raises (ValueError ):
473
473
getattr (clf , "feature_importances_" )
474
474
@@ -653,7 +653,6 @@ def test_min_samples_leaf():
653
653
est .fit (X , y )
654
654
out = est .tree_ .apply (X )
655
655
node_counts = np .bincount (out )
656
-
657
656
# drop inner nodes
658
657
leaf_count = node_counts [node_counts != 0 ]
659
658
assert np .min (leaf_count ) > 4 , "Failed with {0}" .format (name )
@@ -678,7 +677,7 @@ def check_min_weight_fraction_leaf(name, datasets, sparse=False):
678
677
else :
679
678
X = DATASETS [datasets ]["X" ].astype (np .float32 )
680
679
y = DATASETS [datasets ]["y" ]
681
- rng = np . random . RandomState ( 42 )
680
+
682
681
weights = rng .rand (X .shape [0 ])
683
682
total_weight = np .sum (weights )
684
683
@@ -829,7 +828,7 @@ def test_min_impurity_decrease():
829
828
)
830
829
# Check with a much lower value of 0.0001
831
830
est3 = TreeEstimator (
832
- max_leaf_nodes = max_leaf_nodes , min_impurity_decrease = 0.0001 , random_state = 1
831
+ max_leaf_nodes = max_leaf_nodes , min_impurity_decrease = 0.0001 , random_state = 0
833
832
)
834
833
# Check with a much lower value of 0.1
835
834
est4 = TreeEstimator (
@@ -919,7 +918,6 @@ def test_pickle():
919
918
est2 = pickle .loads (serialized_object )
920
919
assert type (est2 ) == est .__class__
921
920
922
- # score should match before/after pickling
923
921
score2 = est2 .score (X , y )
924
922
assert (
925
923
score == score2
@@ -1033,6 +1031,7 @@ def test_memory_layout():
1033
1031
ALL_TREES .items (), [np .float64 , np .float32 ]
1034
1032
):
1035
1033
est = TreeEstimator (random_state = 0 )
1034
+
1036
1035
# Nothing
1037
1036
X = np .asarray (iris .data , dtype = dtype )
1038
1037
y = iris .target
@@ -1053,11 +1052,6 @@ def test_memory_layout():
1053
1052
y = iris .target
1054
1053
assert_array_equal (est .fit (X , y ).predict (X ), y )
1055
1054
1056
- # Strided
1057
- X = np .asarray (iris .data [::3 ], dtype = dtype )
1058
- y = iris .target [::3 ]
1059
- assert_array_equal (est .fit (X , y ).predict (X ), y )
1060
-
1061
1055
# csr matrix
1062
1056
X = csr_matrix (iris .data , dtype = dtype )
1063
1057
y = iris .target
@@ -1068,6 +1062,11 @@ def test_memory_layout():
1068
1062
y = iris .target
1069
1063
assert_array_equal (est .fit (X , y ).predict (X ), y )
1070
1064
1065
+ # Strided
1066
+ X = np .asarray (iris .data [::3 ], dtype = dtype )
1067
+ y = iris .target [::3 ]
1068
+ assert_array_equal (est .fit (X , y ).predict (X ), y )
1069
+
1071
1070
1072
1071
def test_sample_weight ():
1073
1072
# Check sample weighting.
@@ -1261,7 +1260,7 @@ def test_behaviour_constant_feature_after_splits():
1261
1260
y = [0 , 0 , 0 , 1 , 1 , 2 , 2 , 2 , 3 , 3 , 3 ]
1262
1261
for name , TreeEstimator in ALL_TREES .items ():
1263
1262
# do not check extra random trees
1264
- if all ( _name not in name for _name in [ "ExtraTree" ]) :
1263
+ if "ExtraTree" not in name :
1265
1264
est = TreeEstimator (random_state = 0 , max_features = 1 )
1266
1265
est .fit (X , y )
1267
1266
assert est .tree_ .max_depth == 2
@@ -1587,7 +1586,6 @@ def check_min_weight_leaf_split_level(name):
1587
1586
sample_weight = [0.2 , 0.2 , 0.2 , 0.2 , 0.2 ]
1588
1587
_check_min_weight_leaf_split_level (TreeEstimator , X , y , sample_weight )
1589
1588
1590
- # skip for sparse inputs
1591
1589
_check_min_weight_leaf_split_level (TreeEstimator , csc_matrix (X ), y , sample_weight )
1592
1590
1593
1591
@@ -1646,7 +1644,6 @@ def check_decision_path(name):
1646
1644
# Assert that leaves index are correct
1647
1645
leaves = est .apply (X )
1648
1646
leave_indicator = [node_indicator [i , j ] for i , j in enumerate (leaves )]
1649
-
1650
1647
assert_array_almost_equal (leave_indicator , np .ones (shape = n_samples ))
1651
1648
1652
1649
# Ensure only one leave node per sample
@@ -1933,7 +1930,6 @@ def assert_is_subtree(tree, subtree):
1933
1930
def test_apply_path_readonly_all_trees (name , splitter , X_format ):
1934
1931
dataset = DATASETS ["clf_small" ]
1935
1932
X_small = dataset ["X" ].astype (tree ._tree .DTYPE , copy = False )
1936
-
1937
1933
if X_format == "dense" :
1938
1934
X_readonly = create_memmap_backed_data (X_small )
1939
1935
else :
0 commit comments