<s> from sklearn_pmml . convert import CategoricalFeature <EOL> __author__ = '<STR_LIT>' <EOL> from sklearn . ensemble import RandomForestClassifier <EOL> from sklearn_pmml . convert . model import Schema , ModelMode , ClassifierConverter <EOL> from sklearn_pmml . convert . tree import DecisionTreeConverter <EOL> from sklearn_pmml . convert . utils import estimator_to_converter <EOL> import sklearn_pmml . pmml as pmml <EOL> class RandomForestClassifierConverter ( ClassifierConverter ) : <EOL> def __init__ ( self , estimator , context ) : <EOL> super ( RandomForestClassifierConverter , self ) . __init__ ( estimator , context ) <EOL> assert isinstance ( estimator , RandomForestClassifier ) , '<STR_LIT>' <EOL> assert len ( context . schemas [ Schema . OUTPUT ] ) == <NUM_LIT:1> , '<STR_LIT>' <EOL> def model ( self , verification_data = None ) : <EOL> mining_model = pmml . MiningModel ( functionName = ModelMode . CLASSIFICATION . value ) <EOL> mining_model . append ( self . mining_schema ( ) ) <EOL> mining_model . append ( self . output ( ) ) <EOL> mining_model . append ( self . segmentation ( ) ) <EOL> if verification_data is not None : <EOL> mining_model . append ( self . model_verification ( verification_data ) ) <EOL> return mining_model <EOL> def segmentation ( self ) : <EOL> """<STR_LIT>""" <EOL> segmentation = pmml . Segmentation ( multipleModelMethod = "<STR_LIT>" ) <EOL> for index , est in enumerate ( self . estimator . estimators_ ) : <EOL> s = pmml . Segment ( id = index ) <EOL> s . append ( pmml . True_ ( ) ) <EOL> s . append ( DecisionTreeConverter ( est , self . context , ModelMode . CLASSIFICATION ) . _model ( ) ) <EOL> segmentation . append ( s ) <EOL> return segmentation <EOL> estimator_to_converter [ RandomForestClassifier ] = RandomForestClassifierConverter </s>
