A package to build ensemble for quick experiments.
Project description
Quicksemble
Quicksemble is a simple package to create a stacked ensemble for quick experiments. It is developed in T2P Co., Ltd.
Dependencies
- Numpy
pip install numpy
- Scikit Learn
pip install scikit-learn
- 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.
Source Distribution
Built Distribution
File details
Details for the file quicksemble-0.2.8.tar.gz
.
File metadata
- Download URL: quicksemble-0.2.8.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.27.0 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 951ed8383370cf8ef031d7e1814ebb1ea2da7331952000d44c9e6d5b94d586ea |
|
MD5 | 91113e0ea7edb68e69ac362593c6f849 |
|
BLAKE2b-256 | 6b6ce48bd6c563fe206058c35ddd86b4b2ce2b508ce99a37ba0099d01a627e17 |
File details
Details for the file quicksemble-0.2.8-py3-none-any.whl
.
File metadata
- Download URL: quicksemble-0.2.8-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.27.0 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0cbef814ce65aabf319ba1dcff949057d44fa9fe2c0f1689133318215214d3ff |
|
MD5 | 1a4bda9779979796d8176539a36b1835 |
|
BLAKE2b-256 | fc93b209bd48c4ff5e6ee705e8f4ce05131d48f0d1ab06d7038bc970389fdd4d |