<s> import types <EOL> import numpy as np <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> class Wrapper ( object ) : <EOL> def __init__ ( self , obj ) : <EOL> self . _obj = obj <EOL> def __getattr__ ( self , attr ) : <EOL> if hasattr ( self . _obj , attr ) : <EOL> attr_value = getattr ( self . _obj , attr ) <EOL> if isinstance ( attr_value , types . MethodType ) : <EOL> def callable ( * args , ** kwargs ) : <EOL> return attr_value ( * args , ** kwargs ) <EOL> return callable <EOL> else : <EOL> return attr_value <EOL> else : <EOL> raise AttributeError <EOL> def __getstate__ ( self ) : return self . __dict__ <EOL> def __setstate__ ( self , d ) : self . __dict__ . update ( d ) <EOL> class Estimator ( Wrapper ) : <EOL> def __init__ ( self , estimator ) : <EOL> self . base_estimator_ = estimator <EOL> super ( Estimator , self ) . __init__ ( estimator ) <EOL> def __repr__ ( self ) : <EOL> return repr ( self . base_estimator_ ) <EOL> def fit ( self , x , y , ** kwargs ) : <EOL> return self . base_estimator_ . fit ( x . values , y . values , ** kwargs ) <EOL> def predict_maxprob ( self , x , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . base_estimator_ . predict ( x . values , ** kwargs ) <EOL> def predict ( self , x , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . base_estimator_ . predict ( x . values , ** kwargs ) <EOL> class Probabilities ( Estimator ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , estimator , binary = False ) : <EOL> """<STR_LIT>""" <EOL> self . binary = binary <EOL> super ( Probabilities , self ) . __init__ ( estimator ) <EOL> def __str__ ( self ) : <EOL> return u"<STR_LIT>" % self . base_estimator_ <EOL> def predict ( self , x ) : <EOL> probs = self . base_estimator_ . predict_proba ( x ) <EOL> if probs . shape [ <NUM_LIT:1> ] == <NUM_LIT:2> or self . binary : <EOL> return probs [ : , <NUM_LIT:1> ] <EOL> return probs <EOL> class BinaryProbabilities ( Probabilities ) : <EOL> def __init__ ( self , estimator ) : <EOL> super ( BinaryProbabilities , self ) . __init__ ( estimator , binary = True ) <EOL> class ConstantClassifier ( object ) : <EOL> def __init__ ( self , func ) : <EOL> self . func = func <EOL> self . constant = None <EOL> def fit ( self , x , y , ** kwargs ) : <EOL> self . constant = self . func ( y ) <EOL> def predict ( self , x , ** kwargs ) : <EOL> return np . full ( ( x . shape [ <NUM_LIT:0> ] , ) , int ( self . constant > <NUM_LIT> ) ) <EOL> def predict_proba ( self , x , ** kwargs ) : <EOL> p = np . zeros ( ( x . shape [ <NUM_LIT:0> ] , <NUM_LIT:2> ) ) <EOL> p [ : , <NUM_LIT:0> ] = <NUM_LIT:1> - self . constant <EOL> p [ : , <NUM_LIT:1> ] = self . constant <EOL> return p <EOL> class ConstantRegressor ( object ) : <EOL> def __init__ ( self , func ) : <EOL> self . func = func <EOL> self . constant = None <EOL> def fit ( self , x , y , ** kwargs ) : <EOL> self . constant = self . func ( y ) <EOL> def predict ( self , x , ** kwargs ) : <EOL> return np . full ( ( x . shape [ <NUM_LIT:0> ] , ) , self . constant ) <EOL> def wrap_sklearn_like_estimator ( estimator ) : <EOL> if isinstance ( estimator , Estimator ) : <EOL> return estimator <EOL> elif estimator is None : <EOL> return None <EOL> elif not ( hasattr ( estimator , "<STR_LIT>" ) and ( hasattr ( estimator , "<STR_LIT>" ) <EOL> or hasattr ( estimator , "<STR_LIT>" ) ) ) : <EOL> raise ValueError , "<STR_LIT>" % estimator <EOL> elif hasattr ( estimator , "<STR_LIT>" ) : <EOL> return Probabilities ( estimator ) <EOL> else : <EOL> return Estimator ( estimator ) </s>
