Skip to content

Commit

Permalink
Merge pull request #44 from rasbt/tensorflow08
Browse files Browse the repository at this point in the history
Tensorflow08
  • Loading branch information
rasbt committed Apr 22, 2016
2 parents eb26261 + 5ee198c commit 7f08c72
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 155 deletions.
57 changes: 24 additions & 33 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,29 @@
sudo: required
dist: trusty
language: python
sudo: false
os:
- linux
virtualenv:
system_site_packages: true
env:
matrix:
- PYTHON_VERSION="2.7" LATEST="true"
- PYTHON_VERSION="3.4" LATEST="true"
- PYTHON_VERSION="3.5" LATEST="true"
- PYTHON_VERSION="3.5" NUMPY_VERSION="1.10.4" SCIPY_VERSION="0.17" SKLEARN_VERSION="0.17" PANDAS_VERSION="0.17.1" MATPLOTLIB_VERSION="1.5.1"
- PYTHON_VERSION="3.5" COVERAGE="true" LATEST="true"
- PYTHON_VERSION="2.7" TENSORFLOW="true" LATEST="true"
- PYTHON_VERSION="3.4" TENSORFLOW="true" LATEST="true"
install: source ./ci/.travis_install.sh
script: bash ./ci/.travis_test.sh
matrix:
include:
- python: 3.5
env: LATEST="false" TENSORFLOW="false" COVERAGE="false" NUMPY_VERSION="1.10.4" SCIPY_VERSION="0.17" SKLEARN_VERSION="0.17" PANDAS_VERSION="0.17.1" MATPLOTLIB_VERSION="1.5.1"
- python: 3.5
env: LATEST="true" TENSORFLOW="false" COVERAGE="false"
- python: 3.4
env: LATEST="true" TENSORFLOW="false" COVERAGE="false"
- python: 3.4
env: LATEST="true" TENSORFLOW="true" COVERAGE="false"
- python: 2.7
env: LATEST="true" TENSORFLOW="false" COVERAGE="false"
- python: 2.7
env: LATEST="true" TENSORFLOW="true" COVERAGE="false"
install:
- ci/.travis_install.sh
script:
- echo "test"
after_success:
# Ignore coveralls failures as the coveralls server is not very reliable
# but we don't want travis to report a failure in the github UI just
# because the coverage report failed to be published.
- if [[ "$COVERAGE" == "true" ]]; then coveralls || echo "failed"; fi
cache: apt
sudo: false
- if [[ "${COVERAGE}" == "true" ]]; then coveralls || echo "failed"; fi
notifications:
email:
recipients:
- [email protected]
email:
recipients:
- [email protected]
on_success: always
on_failure: always

addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- gcc-4.8
- g++-4.8
117 changes: 32 additions & 85 deletions ci/.travis_install.sh
Original file line number Diff line number Diff line change
@@ -1,102 +1,49 @@
#!/bin/bash
# This script is meant to be called by the "install" step defined in
# .travis.yml. See http://docs.travis-ci.com/ for more details.
# The behavior of the script is controlled by environment variabled defined
# in the .travis.yml in the top level folder of the project.

# License: 3-clause BSD


#!/usr/bin/env bash

set -e

# Fix the compilers to workaround avoid having the Python 3.4 build
# lookup for g++44 unexpectedly.
#export CC=gcc
#export CXX=g++

# Deactivate the travis-provided virtual environment and setup a
# conda-based environment instead
deactivate

# Use the miniconda installer for faster download / install of conda
# itself
if [[ "$PYTHON_VERSION" == "2.7" ]]; then
wget http://repo.continuum.io/miniconda/Miniconda2-4.0.5-Linux-x86_64.sh \
-O miniconda.sh
if [ "${TRAVIS_PYTHON_VERSION}" == "2.7" ]; then
wget https://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh;
else
wget http://repo.continuum.io/miniconda/Miniconda3-4.0.5-Linux-x86_64.sh \
-O miniconda.sh
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
fi

wget http://repo.continuum.io/miniconda/Miniconda-3.16.0-Linux-x86_64.sh \
-O miniconda.sh
chmod +x miniconda.sh && ./miniconda.sh -b
export PATH=/home/travis/miniconda/bin:$PATH
conda update --yes conda

# Configure the conda environment and put it in the path using the
# provided versions
bash miniconda.sh -b -p $HOME/miniconda
export PATH="$HOME/miniconda/bin:$PATH"
hash -r
conda config --set always_yes yes --set changeps1 no
conda update -q conda
conda info -a


if [[ "$LATEST" == "true" ]]; then
conda create -n testenv --yes python=$PYTHON_VERSION pip nose \
numpy scipy scikit-learn cython pandas matplotlib
if [ "${LATEST}" = "true" ]; then
conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION numpy scipy matplotlib pandas scikit-learn;
else
conda create -n testenv --yes python=$PYTHON_VERSION pip nose \
numpy=$NUMPY_VERSION scipy=$SCIPY_VERSION \
scikit-learn=$SKLEARN_VERSION \
pandas=$PANDAS_VERSION \
matplotlib=$MATPLOTLIB_VERSION cython
conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION numpy=$NUMPY_VERSION scipy=$SCIPY_VERSION matplotlib=$MATPLOTLIB_VERSION pandas=$PANDAS_VERSION scikit-learn=$SKLEARN_VERSION;
fi

source activate test-environment

source activate testenv

pip install nose-exclude
pip install nose nose-exclude;

if [[ "$COVERAGE" == "true" ]]; then
pip install coverage coveralls
if [ "${COVERAGE}" = "true" ]; then
pip install coverage coveralls;
fi

if [[ "$TENSORFLOW" == "true" ]]; then
# workaround for "Cannot remove entries from nonexistent file /home/travis/miniconda/envs/testenv/lib/python3.4/site-packages/easy-install.pth"
conda update setuptools --yes
curl https://bootstrap.pypa.io/ez_setup.py -o - | python
case "$TRAVIS_OS_NAME" in
"linux")
case "$PYTHON_VERSION" in
"2.7")
pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.7.1-cp27-none-linux_x86_64.whl
;;
"3.4")
pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.7.1-cp34-none-linux_x86_64.whl
;;
esac
;;
"osx")
case "$PYTHON_VERSION" in
"2.7")
pip install --upgrade https://storage.googleapis.com/tensorflow/mac/tensorflow-0.7.1-cp27-none-any.whl
;;
"3.5")
pip install --upgrade https://storage.googleapis.com/tensorflow/mac/tensorflow-0.7.1-cp35-none-any.whl
;;
esac
;;
esac
fi

# Build mlxtend in the install.sh script to collapse the verbose
# build output in the travis output when it succeeds.

if [[ "$TENSORFLOW" == "true" ]]; then
python -c "import tensorflow; print('tensorflow %s' % tensorflow.__version__)"
python --version
python -c "import pandas; print('pandas %s' % pandas.__version__)";
python -c "import matplotlib; print('matplotlib %s' % matplotlib.__version__)";
python -c "import numpy; print('numpy %s' % numpy.__version__)"
python -c "import scipy; print('scipy %s' % scipy.__version__)"

if [ "${TENSORFLOW}" = "true" ]; then
if [ "${TRAVIS_PYTHON_VERSION}" = "2.7" ]; then
pip install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0-cp27-none-linux_x86_64.whl;
else
pip install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0-cp34-cp34m-linux_x86_64.whl;
fi
python -c "import tensorflow; print('tensorflow %s' % tensorflow.__version__)";
else
python -c "import sklearn; print('sklearn %s' % sklearn.__version__)"
python -c "import pandas; print('pandas %s' % pandas.__version__)"
python -c "import matplotlib; print('matplotlib %s' % matplotlib.__version__)"
python -c "import sklearn; print('sklearn %s' % sklearn.__version__)";
fi

# install mlxtend
python setup.py install #build_ext --inplace
python setup.py install;
27 changes: 6 additions & 21 deletions ci/.travis_test.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,16 @@
#!/bin/bash
# This script is meant to be called by the "script" step defined in
# .travis.yml. See http://docs.travis-ci.com/ for more details.
# The behavior of the script is controlled by environment variabled defined
# in the .travis.yml in the top level folder of the project.

# License: 3-clause BSD
#!/usr/bin/env bash

set -e

python --version
python -c "import numpy; print('numpy %s' % numpy.__version__)"
python -c "import scipy; print('scipy %s' % scipy.__version__)"


if [[ "$TENSORFLOW" == "true" ]]; then
python -c "import tensorflow; print('tensorflow %s' % tensorflow.__version__)"
nosetests -s -v mlxtend.tf_classifier --nologcapture
if [ "$TENSORFLOW" == "true" ]; then
if [[ "$COVERAGE" == "true" ]]; then
nosetests -s -v mlxtend.tf_classifier --nologcapture --with-coverage
else
nosetests -s -v mlxtend.tf_classifier --nologcapture
else
python -c "import sklearn; print('sklearn %s' % sklearn.__version__)"
python -c "import pandas; print('pandas %s' % pandas.__version__)"
python -c "import matplotlib; print('matplotlib %s' % matplotlib.__version__)"

if [[ "$COVERAGE" == "true" ]]; then
nosetests -s -v --with-coverage --exclude-dir=mlxtend/tf_classifier --exclude-dir=mlxtend/data --exclude-dir=mlxtend/general_plotting

else
nosetests -s -v --exclude-dir=mlxtend/tf_classifier --exclude-dir=mlxtend/data --exclude-dir=mlxtend/general_plotting
fi

fi
103 changes: 87 additions & 16 deletions docs/sources/user_guide/classifier/EnsembleVoteClassifier.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"output_type": "stream",
"text": [
"Sebastian Raschka \n",
"last updated: 2016-04-19 \n",
"last updated: 2016-04-20 \n",
"\n",
"CPython 3.5.1\n",
"IPython 4.0.3\n",
Expand Down Expand Up @@ -493,7 +493,7 @@
},
{
"cell_type": "code",
"execution_count": 33,
"execution_count": 2,
"metadata": {
"collapsed": false
},
Expand All @@ -502,18 +502,18 @@
"name": "stdout",
"output_type": "stream",
"text": [
"0.953 (+/-0.013) for {'pipeline__logreg__C': 1.0, 'pipeline__sfs__k_features': 1, 'randomforestclassifier__n_estimators': 20}\n",
"0.947 (+/-0.017) for {'pipeline__logreg__C': 1.0, 'pipeline__sfs__k_features': 1, 'randomforestclassifier__n_estimators': 200}\n",
"0.953 (+/-0.013) for {'pipeline__logreg__C': 1.0, 'pipeline__sfs__k_features': 2, 'randomforestclassifier__n_estimators': 20}\n",
"0.947 (+/-0.017) for {'pipeline__logreg__C': 1.0, 'pipeline__sfs__k_features': 2, 'randomforestclassifier__n_estimators': 200}\n",
"0.953 (+/-0.013) for {'pipeline__logreg__C': 1.0, 'pipeline__sfs__k_features': 3, 'randomforestclassifier__n_estimators': 20}\n",
"0.953 (+/-0.017) for {'pipeline__logreg__C': 1.0, 'pipeline__sfs__k_features': 3, 'randomforestclassifier__n_estimators': 200}\n",
"0.947 (+/-0.017) for {'pipeline__logreg__C': 100.0, 'pipeline__sfs__k_features': 1, 'randomforestclassifier__n_estimators': 20}\n",
"0.953 (+/-0.017) for {'pipeline__logreg__C': 100.0, 'pipeline__sfs__k_features': 1, 'randomforestclassifier__n_estimators': 200}\n",
"0.947 (+/-0.017) for {'pipeline__logreg__C': 100.0, 'pipeline__sfs__k_features': 2, 'randomforestclassifier__n_estimators': 20}\n",
"0.947 (+/-0.017) for {'pipeline__logreg__C': 100.0, 'pipeline__sfs__k_features': 2, 'randomforestclassifier__n_estimators': 200}\n",
"0.960 (+/-0.012) for {'pipeline__logreg__C': 100.0, 'pipeline__sfs__k_features': 3, 'randomforestclassifier__n_estimators': 20}\n",
"0.953 (+/-0.017) for {'pipeline__logreg__C': 100.0, 'pipeline__sfs__k_features': 3, 'randomforestclassifier__n_estimators': 200}\n"
"0.953 (+/-0.013) for {'pipeline__sfs__k_features': 1, 'pipeline__logreg__C': 1.0, 'randomforestclassifier__n_estimators': 20}\n",
"0.947 (+/-0.017) for {'pipeline__sfs__k_features': 1, 'pipeline__logreg__C': 1.0, 'randomforestclassifier__n_estimators': 200}\n",
"0.953 (+/-0.013) for {'pipeline__sfs__k_features': 2, 'pipeline__logreg__C': 1.0, 'randomforestclassifier__n_estimators': 20}\n",
"0.947 (+/-0.017) for {'pipeline__sfs__k_features': 2, 'pipeline__logreg__C': 1.0, 'randomforestclassifier__n_estimators': 200}\n",
"0.953 (+/-0.013) for {'pipeline__sfs__k_features': 3, 'pipeline__logreg__C': 1.0, 'randomforestclassifier__n_estimators': 20}\n",
"0.953 (+/-0.017) for {'pipeline__sfs__k_features': 3, 'pipeline__logreg__C': 1.0, 'randomforestclassifier__n_estimators': 200}\n",
"0.947 (+/-0.017) for {'pipeline__sfs__k_features': 1, 'pipeline__logreg__C': 100.0, 'randomforestclassifier__n_estimators': 20}\n",
"0.953 (+/-0.017) for {'pipeline__sfs__k_features': 1, 'pipeline__logreg__C': 100.0, 'randomforestclassifier__n_estimators': 200}\n",
"0.947 (+/-0.017) for {'pipeline__sfs__k_features': 2, 'pipeline__logreg__C': 100.0, 'randomforestclassifier__n_estimators': 20}\n",
"0.947 (+/-0.017) for {'pipeline__sfs__k_features': 2, 'pipeline__logreg__C': 100.0, 'randomforestclassifier__n_estimators': 200}\n",
"0.960 (+/-0.012) for {'pipeline__sfs__k_features': 3, 'pipeline__logreg__C': 100.0, 'randomforestclassifier__n_estimators': 20}\n",
"0.953 (+/-0.017) for {'pipeline__sfs__k_features': 3, 'pipeline__logreg__C': 100.0, 'randomforestclassifier__n_estimators': 200}\n"
]
}
],
Expand Down Expand Up @@ -640,7 +640,7 @@
},
{
"cell_type": "code",
"execution_count": 44,
"execution_count": 3,
"metadata": {
"collapsed": false
},
Expand All @@ -651,7 +651,7 @@
"array([0, 1, 2])"
]
},
"execution_count": 44,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -668,6 +668,77 @@
"eclf.fit(X, y).predict(X[[1, 51, 149]])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Furthermore, we can fit the `SequentialFeatureSelector` separately, outside the grid search hyperparameter optimization pipeline. Here, we determine the best features first, and then we construct a pipeline using these \"fixed,\" best features as seed for the `ColumnSelector`:"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Features: 2/2"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Best features (1, 3)\n"
]
}
],
"source": [
"sfs1 = SequentialFeatureSelector(clf1, \n",
" k_features=2,\n",
" forward=True, \n",
" floating=False, \n",
" scoring='accuracy',\n",
" print_progress=True,\n",
" cv=0)\n",
"\n",
"sfs1.fit(X, y)\n",
"\n",
"print('Best features', sfs1.k_feature_idx_)\n",
"\n",
"col_sel = ColumnSelector(cols=sfs1.k_feature_idx_)\n",
"\n",
"clf1_pipe = Pipeline([('sel', col_sel),\n",
" ('logreg', clf1)])"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"array([0, 1, 2])"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"eclf = EnsembleVoteClassifier(clfs=[clf1_pipe, clf2, clf3], voting='soft')\n",
"eclf.fit(X, y).predict(X[[1, 51, 149]])"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down

0 comments on commit 7f08c72

Please sign in to comment.