Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/shaharazulay/unicorn
Browse files Browse the repository at this point in the history
  • Loading branch information
shaharazulay committed Sep 1, 2018
2 parents 1ffc560 + 0264421 commit 8bd72ff
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 68 deletions.
7 changes: 2 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@ python:
install:
- pip install codecov
- pip install coverage
# magellan
- cd magellan
- pip install -r requirements.txt
- python setup.py install
- cd ..

script:
# magellan
- cd magellan
- python setup.py test
# magellan coverage
- cd magellan
- coverage run test/_test.py

after_success:
Expand Down
5 changes: 1 addition & 4 deletions docs/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@ Unicorn
Shahar Azulay, Tali Raveh, Ariel Hanemann, Yossi Cohen


|Travis|_ |Codecov|_ |Python27|_ |Python35|_ |License|_
|Travis|_ |Python27|_ |Python35|_ |License|_

.. |License| image:: https://img.shields.io/badge/license-BSD--3--Clause-brightgreen.svg
.. _License: https://github.com/shaharazulay/unicorn/blob/master/LICENSE

.. |Travis| image:: https://travis-ci.org/shaharazulay/unicorn.svg?branch=master
.. _Travis: https://travis-ci.org/shaharazulay/unicorn

.. |Codecov| image:: https://codecov.io/gh/shaharazulay/unicorn/branch/master/graph/badge.svg
.. _Codecov: https://codecov.io/gh/shaharazulay/unicorn

.. |Python27| image:: https://img.shields.io/badge/python-2.7-blue.svg
.. _Python27:
Expand Down
7 changes: 3 additions & 4 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ Contents
self

.. toctree::
:maxdepth: 3

overview
magellan_link
:maxdepth: 4

overview
MageLlan <magellan_link>
2 changes: 1 addition & 1 deletion docs/magellan_link.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
.. include:: ../magellan/docs/index.rst
.. include:: ../magellan/docs/overview.rst
60 changes: 6 additions & 54 deletions magellan/docs/overview.rst
Original file line number Diff line number Diff line change
@@ -1,69 +1,21 @@
.. _adapting:

The Stacking Ensemble
MageLlan
===================

Background
-----

Stacking (sometimes called stacked generalization or bagging) is an ensemble meta-algorithm that attempts to improve a model's
predictive power by harnessing multiple models (perferably different in nature) to a unified pipeline.
<TBD>

The Stacking method is a very general name that is sometimes used to describe different methods to crete the unfied pipeline.
Here, we focus on a Stacking ensemble which uses the multiple models predict the target, while unifing them using a
meta-level regressor - which learns how to annotate proper weights to the predictions of the models under it.

A simpler type of Stacking might have been to average the predictions of the different models (similar to Random Forest,
but perhaps without the limitation of a single-type model).

In true Stacking the "stacker" or the meta-level regressor can also perform learning, where models which are proven to be
less efficient in predicting the data are provided lower weight in the final prediction.

.. image:: _static/figure_001.jpg

*[1] high-level description of the stacking ensemble*



Getting it Wrong
The Method
-----

The major problem in creating a proper Stacking ensemble is getting it right.
The wrong way to perform stacking would be to

1. **Train** the first level models over the target.

2. Get the first level models predictions over the inputs.

3. **Train** the meta-level Stacker over the predictions of the first level models.
<TBD>

Why would that be the wrong way to go?

**Overfitting**

Our meta-level regressor would be exposed to severe overfitting from one of the first level models.
For example, if one of five first level models would be highly overfitted to the target, practically "storing"
the y target it is showns in train time for test time.
The meta-level model, trained over the same target would see this model as excellent - predicting the target y
with impressive accuracy almost everytime.

This will result in a hight weight to this model, making the entire pipeline useless in test time.


The Solution
Results
-----

The solution is never using the train abilities of the first level model - but using their abilities in test.
What does it mean? it means the meta-level model would never be exposed to a y_hat generated by any first level
model where the actual target sample representing this y_hat in the data was given to that model in training.

Each model will deliever its predictions in a "cross_val_predict" manner (in sklearn terms). If it's a great model,
it will demonstrate great generalization skills making its test-time predictions valuable to the meta-level regressor.
If it's a highly overfitted model - the test-time predictions it will hand down the line will be showns for their true
abilities, causing it to recieve a low weight.

How do we achieve that? internal cross validation.

.. image:: _static/figure_002.jpg

*[1] achienving stacking ensemble using internal cross-validation*
<TBD>

0 comments on commit 8bd72ff

Please sign in to comment.