Skip to content

Quicksemble is a simple package to create a stacked ensemble for quick experiments

Notifications You must be signed in to change notification settings

SubigyaPanta/quicksemble

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Quicksemble

Downloads

Quicksemble is a simple package to create a stacked ensemble for quick experiments. It is developed in T2P Co., Ltd.

Dependencies

  1. Numpy pip install numpy
  2. Scikit Learn pip install scikit-learn
  3. Xgboost pip install xgboost

Installation

pip install quicksemble

Basic Usage

from sklearn.ensemble import RandomForestClassifier
from xgboost import XGBClassifier
from quicksemble.ensembler import Ensembler

#
# Define train and test dataset here
#

models = [
    RandomForestClassifier(random_state=21),
    XGBClassifier(random_state=21)
]
# Default meta classifier is LogisticRegression. Hence it is weighted voting.
ensemble = Ensembler(models)
ensemble.fit(X_train, y_train)
ensemble.predict(X_test)

To change the default meta classifer:

from sklearn.ensemble import RandomForestClassifier
from xgboost import XGBClassifier
from quicksemble.ensembler import Ensembler

#
# Define train and test dataset here
#

models = [
    RandomForestClassifier(random_state=21),
    XGBClassifier(random_state=21)
]

# Use Neural Network as meta classifier
ensemble = Ensembler(models, meta_model=MLPClassifier())
ensemble.fit(X_train, y_train)
ensemble.predict(X_test)

By default, Base models use "hard" voting, i.e., it outputs predictions of the base models. We can switch it to "soft" voting, i.e., it outputs probabilities of each class by the base model.

To change voting style:

from sklearn.ensemble import RandomForestClassifier
from xgboost import XGBClassifier
from quicksemble.ensembler import Ensembler

#
# Define train and test dataset here
#

models = [
    RandomForestClassifier(random_state=21),
    XGBClassifier(random_state=21)
]

# Use soft voting. 
ensemble = Ensembler(models, voting='soft')
ensemble.fit(X_train, y_train)
ensemble.predict(X_test)

To view output of intermediary state i.e., output of base layers (layer 1) that is going into meta layer (layer 2). Internally, it uses Pipelines from scikit-learn. So, feel free to read docs about pipelines.

ensemble = Ensembler(models, voting='soft')
ensemble.fit(X_train, y_train)

# This line will output the values. Note that you need to fit it first.
ensemble.ensemble.named_steps['base_layer'].transform(X_train)

For already saved models, use modelpaths. Note that it should be pickled.

es = Ensembler(modelpaths=[
            'rf.pkl',
            'xg.pkl'
    ])
es.fit(X_train, y_train)
es.predict(X_train)

About

Quicksemble is a simple package to create a stacked ensemble for quick experiments

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages