Skip to content

Commit c056567

Browse files
committed
iter
1 parent cc66b75 commit c056567

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

build_tools/travis/install.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ if [[ "$DISTRIB" == "conda" ]]; then
3939
conda create -n testenv --yes python=$PYTHON_VERSION pip
4040
source activate testenv
4141
conda install --yes numpy=$NUMPY_VERSION scipy=$SCIPY_VERSION
42-
conda install --yes pandas keras
42+
# only install optional dependency in python 3.6
43+
if [[ $PYTHON_VERSION == "3.6" ]]; then
44+
conda install --yes pandas keras
45+
fi
4346

4447
if [[ "$SKLEARN_VERSION" == "master" ]]; then
4548
conda install --yes cython
@@ -70,7 +73,7 @@ python --version
7073
python -c "import numpy; print('numpy %s' % numpy.__version__)"
7174
python -c "import scipy; print('scipy %s' % scipy.__version__)"
7275

73-
python setup.py develop
76+
pip install -e .
7477
ccache --show-stats
7578
# Useful for debugging how ccache is used
7679
# cat $CCACHE_LOGFILE

imblearn/keras/_generator.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
"""Implement generators for ``keras`` which will balance the data."""
22
from __future__ import division
33

4-
import keras
4+
try:
5+
import keras
6+
ParentClass = keras.utils.Sequence
7+
HAS_KERAS = True
8+
except ImportError:
9+
ParentClass = object
10+
HAS_KERAS = False
511

612
from scipy.sparse import issparse
713

@@ -16,7 +22,7 @@
1622
from ..tensorflow import balanced_batch_generator as tf_bbg
1723

1824

19-
class BalancedBatchGenerator(keras.utils.Sequence):
25+
class BalancedBatchGenerator(ParentClass):
2026
"""Create balanced batches when training a keras model.
2127
2228
Create a keras ``Sequence`` which is given to ``fit_generator``. The
@@ -90,6 +96,8 @@ class BalancedBatchGenerator(keras.utils.Sequence):
9096
"""
9197
def __init__(self, X, y, sample_weight=None, sampler=None, batch_size=32,
9298
sparse=False, random_state=None):
99+
if not HAS_KERAS:
100+
raise ImportError("'No module named 'keras'")
93101
self.X = X
94102
self.y = y
95103
self.sample_weight = sample_weight

imblearn/keras/tests/test_generator.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55

66
from sklearn.datasets import load_iris
77

8+
keras = pytest.importorskip('keras')
9+
from keras.models import Sequential
10+
from keras.layers import Dense
11+
from keras.utils import to_categorical
12+
813
from imblearn.datasets import make_imbalance
914
from imblearn.under_sampling import ClusterCentroids
1015
from imblearn.under_sampling import NearMiss
1116

1217
from imblearn.keras import BalancedBatchGenerator
1318
from imblearn.keras import balanced_batch_generator
1419

15-
keras = pytest.importorskip('keras')
16-
from keras.models import Sequential
17-
from keras.layers import Dense
18-
from keras.utils import to_categorical
19-
2020
iris = load_iris()
2121
X, y = make_imbalance(iris.data, iris.target, {0: 30, 1: 50, 2: 40})
2222
y = to_categorical(y, 3)

0 commit comments

Comments
 (0)