Use a different value based score

What I'm trying to do is build a regressor based on the value in the function. That is, I have several columns where one of them is more important (let it be gender) (of course, it differs from the target value of Y).

I want to say:
- If gender- Male, use randomForest regression
- Else use another regression

Do you have any ideas if this is possible using sklearnor any other library in python?

+4
source share
2 answers

, . , gender . -

class MyRegressor():
    '''uses different regressors internally'''
    def __init__(self):
        self.randomForest = initializeRandomForest()
        self.kNN = initializekNN()

    def fit(self, X, y):
        '''calls the appropriate regressors'''
        X1 = X[X[:,0] == 1]
        y1 = y[X[:,0] == 1]
        X2 = X[X[:,0] != 1]
        y2 = y[X[:,0] != 1]
        self.randomForest.fit(X1, y1)
        self.kNN.fit(X2, y2)

    def predict(self, X):
        '''predicts values using regressors internally'''
        results = np.zeros(X.shape[0])
        results[X[:,0]==1] = self.randomForest.predict(X[X[:,0] == 1])
        results[X[:,0]!=1] = self.kNN.predict(X[X[:,0] != 1])

        return results
+2

Python, . , . , member = true, / randomForest . false / .

0

Source: https://habr.com/ru/post/1626863/


All Articles