Paste
Pasted as Python by SSSSS ( 13 years ago )
class HierarchicalRegressor(object):
'''
Customized regression object. Predicts Y=BER of packet. Outputs Y=-1.0 if packet was not received.
Expects scaled training data for best results
'''
def __init__(self, n_estimators=10, max_depth=None, min_samples_split=1, random_state=0,**kwargs):
'''
Constructor
'''
self.reg=RandomForestRegressor(n_estimators, max_depth, min_samples_split, random_state, n_jobs=1, **kwargs)
self.clf=RandomForestClassifier(n_estimators, max_depth, min_samples_split, random_state,n_jobs=1, **kwargs)
pass
def _process(self, X,Y):
self.X=X
self.Y_class=np.array(map(lambda x: x==-1.0 and -1.0 or 1.0, Y)) #maps Y to -1.0 or +1.0
self.X_class=X
self.Y_reg=Y[self.Y_class==1.0]
self.X_reg=X[self.Y_class==1.0]
def fit(self, X, Y):
self._process(X, Y)
self.clf.fit(self.X_class, self.Y_class)
self.reg.fit(self.X_reg,self.Y_reg)
return self
Revise this Paste
Children: 51863