bricks icon indicating copy to clipboard operation
bricks copied to clipboard

[MODULE] - Random search active learner

Open jhoetter opened this issue 3 years ago • 1 comments

Description Sklearn-based random search to train an active learner classification head

Implementation

from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import RandomizedSearchCV

class ActiveLearner:
    
    def __init__(self, base_classifier, pool_size, query_strategy):
        self.base_classifier = RandomForestClassifier()
        self.pool_size = pool_size
        self.query_strategy = query_strategy
        
    def select_next_sample(self, X_pool, Y_pool):
        if self.query_strategy == "uncertainty":
            pass
        elif self.query_strategy == "diversity":
            pass
        
    def fit(self, X_train, y_train, X_test, y_test):
        self.base_classifier.fit(X_train, y_train)
        y_pred = self.base_classifier.predict_proba(X_test)
        
        return y_pred

def randomSearch():
    
    param_grid = {
        "n_estimators": [10, 50, 100],
        "pool_size": [50, 100, 500]
    }
    
    rf_classifier = RandomForestClassifier()
    
    active_learner = ActiveLearner(base_classifier=rf_classifier,
                                   pool_size=500,
                                   query_strategy='uncertainty')
    
    random_search = RandomizedSearchCV(estimator=active_learner,
                               param_grid=param_grid,
                               scoring='accuracy',
                               n_iter=100)
    
    # define the training data and test data
    
    grid_search.fit(X_train, y_train)
    y_pred = grid_search.predict(X_test)
    
    return y_pred

Additional context

jhoetter avatar Nov 07 '22 22:11 jhoetter

image

Currently not useable in refinery as the integrator input is still to be implemented

JWittmeyer avatar Jan 19 '24 11:01 JWittmeyer