Skip to content

Commit

Permalink
DOC fix AttributeError in Sequential object - predict_proba (scikit-l…
Browse files Browse the repository at this point in the history
…earn-contrib#993)

Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com>
  • Loading branch information
Foxglove144 and glemaitre authored Jul 8, 2023
1 parent 2b126e3 commit f14033b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions examples/applications/porto_seguro_keras_under_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,23 @@ def wrapper(*args, **kwds):
###############################################################################
# The first model will be trained using the ``fit`` method and with imbalanced
# mini-batches.

import tensorflow
from sklearn.metrics import roc_auc_score
from sklearn.utils import parse_version

tf_version = parse_version(tensorflow.__version__)


@timeit
def fit_predict_imbalanced_model(X_train, y_train, X_test, y_test):
model = make_model(X_train.shape[1])
model.fit(X_train, y_train, epochs=2, verbose=1, batch_size=1000)
y_pred = model.predict_proba(X_test, batch_size=1000)
if tf_version < parse_version("2.6"):
# predict_proba was removed in tensorflow 2.6
predict_method = "predict_proba"
else:
predict_method = "predict"
y_pred = getattr(model, predict_method)(X_test, batch_size=1000)
return roc_auc_score(y_test, y_pred)


Expand Down

0 comments on commit f14033b

Please sign in to comment.