@@ -112,19 +112,21 @@ class BalancedBatchGenerator(*ParentClass):
112
112
>>> class_dict = dict()
113
113
>>> class_dict[0] = 30; class_dict[1] = 50; class_dict[2] = 40
114
114
>>> X, y = make_imbalance(iris.data, iris.target, class_dict)
115
- >>> import keras
116
- >>> y = keras.utils.to_categorical(y, 3)
117
- >>> model = keras.models.Sequential()
118
- >>> model.add(keras.layers.Dense(y.shape[1], input_dim=X.shape[1],
119
- ... activation='softmax'))
115
+ >>> import tensorflow
116
+ >>> y = tensorflow.keras.utils.to_categorical(y, 3)
117
+ >>> model = tensorflow.keras.models.Sequential()
118
+ >>> model.add(
119
+ ... tensorflow.keras.layers.Dense(
120
+ ... y.shape[1], input_dim=X.shape[1], activation='softmax'
121
+ ... )
122
+ ... )
120
123
>>> model.compile(optimizer='sgd', loss='categorical_crossentropy',
121
124
... metrics=['accuracy'])
122
125
>>> from imblearn.keras import BalancedBatchGenerator
123
126
>>> from imblearn.under_sampling import NearMiss
124
127
>>> training_generator = BalancedBatchGenerator(
125
128
... X, y, sampler=NearMiss(), batch_size=10, random_state=42)
126
- >>> callback_history = model.fit_generator(generator=training_generator,
127
- ... epochs=10, verbose=0)
129
+ >>> callback_history = model.fit(training_generator, epochs=10, verbose=0)
128
130
"""
129
131
130
132
# flag for keras sequence duck-typing
@@ -264,21 +266,23 @@ def balanced_batch_generator(
264
266
>>> class_dict[0] = 30; class_dict[1] = 50; class_dict[2] = 40
265
267
>>> from imblearn.datasets import make_imbalance
266
268
>>> X, y = make_imbalance(X, y, class_dict)
267
- >>> import keras
268
- >>> y = keras.utils.to_categorical(y, 3)
269
- >>> model = keras.models.Sequential()
270
- >>> model.add(keras.layers.Dense(y.shape[1], input_dim=X.shape[1],
271
- ... activation='softmax'))
269
+ >>> import tensorflow
270
+ >>> y = tensorflow.keras.utils.to_categorical(y, 3)
271
+ >>> model = tensorflow.keras.models.Sequential()
272
+ >>> model.add(
273
+ ... tensorflow.keras.layers.Dense(
274
+ ... y.shape[1], input_dim=X.shape[1], activation='softmax'
275
+ ... )
276
+ ... )
272
277
>>> model.compile(optimizer='sgd', loss='categorical_crossentropy',
273
278
... metrics=['accuracy'])
274
279
>>> from imblearn.keras import balanced_batch_generator
275
280
>>> from imblearn.under_sampling import NearMiss
276
281
>>> training_generator, steps_per_epoch = balanced_batch_generator(
277
282
... X, y, sampler=NearMiss(), batch_size=10, random_state=42)
278
- >>> callback_history = model.fit_generator(generator=training_generator,
279
- ... steps_per_epoch=steps_per_epoch,
280
- ... epochs=10, verbose=0)
281
-
283
+ >>> callback_history = model.fit(training_generator,
284
+ ... steps_per_epoch=steps_per_epoch,
285
+ ... epochs=10, verbose=0)
282
286
"""
283
287
284
288
return tf_bbg (
0 commit comments