Skip to main content

A package to build ensemble for quick experiments.

Project description

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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for quicksemble, version 0.2.8
Filename, size File type Python version Upload date Hashes
Filename, size quicksemble-0.2.8-py3-none-any.whl (5.1 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size quicksemble-0.2.8.tar.gz (4.4 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page