<s> from brew . base import Ensemble <EOL> from brew . base import FeatureSubsamplingTransformer <EOL> from brew . base import BrewClassifier <EOL> from brew . combination . combiner import Combiner <EOL> from sklearn . tree import DecisionTreeClassifier <EOL> import sklearn <EOL> from brew . combination . combiner import Combiner <EOL> from brew . combination . rules import majority_vote_rule <EOL> from . base import PoolGenerator <EOL> import numpy as np <EOL> from sklearn . ensemble import BaggingClassifier <EOL> class RandomSubspace ( PoolGenerator ) : <EOL> def __init__ ( self , base_classifier = None , n_classifiers = <NUM_LIT:100> , combination_rule = '<STR_LIT>' , max_features = <NUM_LIT:0.5> ) : <EOL> self . base_classifier = base_classifier <EOL> self . n_classifiers = n_classifiers <EOL> self . combiner = Combiner ( rule = combination_rule ) <EOL> self . classifiers = None <EOL> self . ensemble = None <EOL> self . max_features = max_features <EOL> def fit ( self , X , y ) : <EOL> self . ensemble = Ensemble ( ) <EOL> for i in range ( self . n_classifiers ) : <EOL> chosen_features = np . random . choice ( X . shape [ <NUM_LIT:1> ] , int ( np . ceil ( X . shape [ <NUM_LIT:1> ] * self . max_features ) ) , replace = False ) <EOL> transformer = FeatureSubsamplingTransformer ( features = chosen_features ) <EOL> classifier = BrewClassifier ( classifier = sklearn . base . clone ( self . base_classifier ) , transformer = transformer ) <EOL> classifier . fit ( X , y ) <EOL> self . ensemble . add ( classifier ) <EOL> return <EOL> def predict ( self , X ) : <EOL> out = self . ensemble . output ( X ) <EOL> return self . combiner . combine ( out ) </s>
