<s> """<STR_LIT>""" <EOL> from re import finditer <EOL> from numpy . testing import assert_equal <EOL> from nose . tools import assert_raises <EOL> from sklearn . tree import DecisionTreeClassifier , DecisionTreeRegressor <EOL> from sklearn . ensemble import GradientBoostingClassifier <EOL> from sklearn . tree import export_graphviz <EOL> from sklearn . externals . six import StringIO <EOL> from sklearn . utils . testing import assert_in <EOL> X = [ [ - <NUM_LIT:2> , - <NUM_LIT:1> ] , [ - <NUM_LIT:1> , - <NUM_LIT:1> ] , [ - <NUM_LIT:1> , - <NUM_LIT:2> ] , [ <NUM_LIT:1> , <NUM_LIT:1> ] , [ <NUM_LIT:1> , <NUM_LIT:2> ] , [ <NUM_LIT:2> , <NUM_LIT:1> ] ] <EOL> y = [ - <NUM_LIT:1> , - <NUM_LIT:1> , - <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ] <EOL> y2 = [ [ - <NUM_LIT:1> , <NUM_LIT:1> ] , [ - <NUM_LIT:1> , <NUM_LIT:1> ] , [ - <NUM_LIT:1> , <NUM_LIT:1> ] , [ <NUM_LIT:1> , <NUM_LIT:2> ] , [ <NUM_LIT:1> , <NUM_LIT:2> ] , [ <NUM_LIT:1> , <NUM_LIT:3> ] ] <EOL> w = [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> y_degraded = [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ] <EOL> def test_graphviz_toy ( ) : <EOL> clf = DecisionTreeClassifier ( max_depth = <NUM_LIT:3> , <EOL> min_samples_split = <NUM_LIT:2> , <EOL> criterion = "<STR_LIT>" , <EOL> random_state = <NUM_LIT:2> ) <EOL> clf . fit ( X , y ) <EOL> out = StringIO ( ) <EOL> export_graphviz ( clf , out_file = out ) <EOL> contents1 = out . getvalue ( ) <EOL> contents2 = '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT:}>' <EOL> assert_equal ( contents1 , contents2 ) <EOL> out = StringIO ( ) <EOL> export_graphviz ( clf , out_file = out , feature_names = [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> contents1 = out . getvalue ( ) <EOL> contents2 = '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT:}>' <EOL> assert_equal ( contents1 , contents2 ) <EOL> out = StringIO ( ) <EOL> export_graphviz ( clf , out_file = out , class_names = [ "<STR_LIT:yes>" , "<STR_LIT>" ] ) <EOL> contents1 = out . getvalue ( ) <EOL> contents2 = '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT:}>' <EOL> assert_equal ( contents1 , contents2 ) <EOL> out = StringIO ( ) <EOL> export_graphviz ( clf , out_file = out , filled = True , impurity = False , <EOL> proportion = True , special_characters = True , rounded = True ) <EOL> contents1 = out . getvalue ( ) <EOL> contents2 = '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT:}>' <EOL> assert_equal ( contents1 , contents2 ) <EOL> out = StringIO ( ) <EOL> export_graphviz ( clf , out_file = out , max_depth = <NUM_LIT:0> , class_names = True ) <EOL> contents1 = out . getvalue ( ) <EOL> contents2 = '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT:}>' <EOL> assert_equal ( contents1 , contents2 ) <EOL> out = StringIO ( ) <EOL> export_graphviz ( clf , out_file = out , max_depth = <NUM_LIT:0> , filled = True , <EOL> node_ids = True ) <EOL> contents1 = out . getvalue ( ) <EOL> contents2 = '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT:}>' <EOL> assert_equal ( contents1 , contents2 ) <EOL> clf = DecisionTreeClassifier ( max_depth = <NUM_LIT:2> , <EOL> min_samples_split = <NUM_LIT:2> , <EOL> criterion = "<STR_LIT>" , <EOL> random_state = <NUM_LIT:2> ) <EOL> clf = clf . fit ( X , y2 , sample_weight = w ) <EOL> out = StringIO ( ) <EOL> export_graphviz ( clf , out_file = out , filled = True , impurity = False ) <EOL> contents1 = out . getvalue ( ) <EOL> contents2 = '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT:}>' <EOL> assert_equal ( contents1 , contents2 ) <EOL> clf = DecisionTreeRegressor ( max_depth = <NUM_LIT:3> , <EOL> min_samples_split = <NUM_LIT:2> , <EOL> criterion = "<STR_LIT>" , <EOL> random_state = <NUM_LIT:2> ) <EOL> clf . fit ( X , y ) <EOL> out = StringIO ( ) <EOL> export_graphviz ( clf , out_file = out , filled = True , leaves_parallel = True , <EOL> rotate = True , rounded = True ) <EOL> contents1 = out . getvalue ( ) <EOL> contents2 = '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT:}>' <EOL> assert_equal ( contents1 , contents2 ) <EOL> clf = DecisionTreeClassifier ( max_depth = <NUM_LIT:3> ) <EOL> clf . fit ( X , y_degraded ) <EOL> out = StringIO ( ) <EOL> export_graphviz ( clf , out_file = out , filled = True ) <EOL> contents1 = out . getvalue ( ) <EOL> contents2 = '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT:}>' <EOL> assert_equal ( contents1 , contents2 ) <EOL> def test_graphviz_errors ( ) : <EOL> clf = DecisionTreeClassifier ( max_depth = <NUM_LIT:3> , min_samples_split = <NUM_LIT:2> ) <EOL> clf . fit ( X , y ) <EOL> out = StringIO ( ) <EOL> assert_raises ( IndexError , export_graphviz , clf , out , feature_names = [ ] ) <EOL> out = StringIO ( ) <EOL> assert_raises ( IndexError , export_graphviz , clf , out , class_names = [ ] ) <EOL> def test_friedman_mse_in_graphviz ( ) : <EOL> clf = DecisionTreeRegressor ( criterion = "<STR_LIT>" , random_state = <NUM_LIT:0> ) <EOL> clf . fit ( X , y ) <EOL> dot_data = StringIO ( ) <EOL> export_graphviz ( clf , out_file = dot_data ) <EOL> clf = GradientBoostingClassifier ( n_estimators = <NUM_LIT:2> , random_state = <NUM_LIT:0> ) <EOL> clf . fit ( X , y ) <EOL> for estimator in clf . estimators_ : <EOL> export_graphviz ( estimator [ <NUM_LIT:0> ] , out_file = dot_data ) <EOL> for finding in finditer ( "<STR_LIT>" , dot_data . getvalue ( ) ) : <EOL> assert_in ( "<STR_LIT>" , finding . group ( ) ) </s>
