From 2259241f4bfd26068d5fe9d6ea3df4508d505bdb Mon Sep 17 00:00:00 2001 From: Pierre Bonami Date: Thu, 2 Jan 2025 12:25:49 -0300 Subject: [PATCH] Fix errors --- Generate_keras_test_network.ipynb | 121 +++--------------- docs/examples/example2_student_admission.py | 1 - notebooks/Janos/Decision Tree.ipynb | 2 +- notebooks/Janos/Random Forest.ipynb | 14 +- .../adversarial_logistic_regression.ipynb | 25 ++-- .../adversarial/adversarial_pytorch.ipynb | 2 +- .../adversarial/adversarial_softmax.ipynb | 22 ++-- src/gurobi_ml/keras/keras.py | 4 +- src/gurobi_ml/modeling/softmax.py | 6 +- src/gurobi_ml/sklearn/mlpregressor.py | 5 +- src/gurobi_ml/torch/sequential.py | 4 +- tests/test_keras/keras_cases.py | 2 +- tests/test_keras/test_keras_formulations.py | 1 + .../test_sklearn/test_sklearn_formulations.py | 14 -- 14 files changed, 59 insertions(+), 164 deletions(-) diff --git a/Generate_keras_test_network.ipynb b/Generate_keras_test_network.ipynb index 587a541f..d8497635 100644 --- a/Generate_keras_test_network.ipynb +++ b/Generate_keras_test_network.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "id": "c8d57e80-9075-4d63-bc36-f9aaad08ea2f", "metadata": {}, "outputs": [], @@ -12,66 +12,55 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "id": "90fa4efb-f9d5-40fb-8e4a-5e3ed1094740", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'3.7.0'" - ] - }, - "execution_count": 13, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "keras.__version__" ] }, { "cell_type": "code", - "execution_count": 14, + "execution_count": null, "id": "5d98d000-661e-4495-bef0-49c5eb180aff", "metadata": {}, "outputs": [], "source": [ "nn = keras.models.Sequential(\n", " [\n", - " keras.layers.InputLayer((8,)),\n", - " keras.layers.Dense(30, activation='relu'),\n", - " keras.layers.Dense(1),\n", + " keras.layers.InputLayer((8,)),\n", + " keras.layers.Dense(30, activation=\"relu\"),\n", + " keras.layers.Dense(1),\n", " ]\n", ")" ] }, { "cell_type": "code", - "execution_count": 15, + "execution_count": null, "id": "ba3cf3ee-bd25-4180-95c0-2ff42d858a34", "metadata": {}, "outputs": [], "source": [ - "nn.compile(loss='mean_squared_error', optimizer='adam')" + "nn.compile(loss=\"mean_squared_error\", optimizer=\"adam\")" ] }, { "cell_type": "code", - "execution_count": 16, + "execution_count": null, "id": "247bd200-8026-4f08-8739-9aabb3c37e99", "metadata": {}, "outputs": [], "source": [ - "(X_train, y_train), (X_test, y_test) = tf.keras.datasets.california_housing.load_data(\n", + "(X_train, y_train), (X_test, y_test) = keras.datasets.california_housing.load_data(\n", " version=\"small\"\n", - ")\n" + ")" ] }, { "cell_type": "code", - "execution_count": 18, + "execution_count": null, "id": "a29325dd-1ab1-4cce-81c0-2528e892adb6", "metadata": {}, "outputs": [], @@ -81,7 +70,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": null, "id": "cbecbd91-e100-4568-9424-efd9e3b6d5fc", "metadata": {}, "outputs": [], @@ -93,100 +82,32 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": null, "id": "5656d2da-ee2d-4a8f-aef3-65876c20193b", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Epoch 1/20\n", - "\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 36ms/step - loss: 51257974784.0000 - val_loss: 48780189696.0000\n", - "Epoch 2/20\n", - "\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 34ms/step - loss: 51058966528.0000 - val_loss: 48779857920.0000\n", - "Epoch 3/20\n", - "\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 30ms/step - loss: 56175738880.0000 - val_loss: 48779501568.0000\n", - "Epoch 4/20\n", - "\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 28ms/step - loss: 48874921984.0000 - val_loss: 48779141120.0000\n", - "Epoch 5/20\n", - "\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 25ms/step - loss: 52104830976.0000 - val_loss: 48778752000.0000\n", - "Epoch 6/20\n", - "\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 41ms/step - loss: 53767278592.0000 - val_loss: 48778342400.0000\n", - "Epoch 7/20\n", - "\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 25ms/step - loss: 51997323264.0000 - val_loss: 48777920512.0000\n", - "Epoch 8/20\n", - "\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 34ms/step - loss: 52127023104.0000 - val_loss: 48777490432.0000\n", - "Epoch 9/20\n", - "\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 31ms/step - loss: 55014318080.0000 - val_loss: 48777023488.0000\n", - "Epoch 10/20\n", - "\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 27ms/step - loss: 50627502080.0000 - val_loss: 48776540160.0000\n", - "Epoch 11/20\n", - "\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 28ms/step - loss: 52081172480.0000 - val_loss: 48776024064.0000\n", - "Epoch 12/20\n", - "\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 21ms/step - loss: 55939633152.0000 - val_loss: 48775487488.0000\n", - "Epoch 13/20\n", - "\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 34ms/step - loss: 51670016000.0000 - val_loss: 48774975488.0000\n", - "Epoch 14/20\n", - "\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 26ms/step - loss: 55131279360.0000 - val_loss: 48774389760.0000\n", - "Epoch 15/20\n", - "\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 30ms/step - loss: 51200266240.0000 - val_loss: 48773820416.0000\n", - "Epoch 16/20\n", - "\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 30ms/step - loss: 53789458432.0000 - val_loss: 48773218304.0000\n", - "Epoch 17/20\n", - "\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 29ms/step - loss: 50551488512.0000 - val_loss: 48772616192.0000\n", - "Epoch 18/20\n", - "\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 28ms/step - loss: 50127593472.0000 - val_loss: 48771956736.0000\n", - "Epoch 19/20\n", - "\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 31ms/step - loss: 48622862336.0000 - val_loss: 48771301376.0000\n", - "Epoch 20/20\n", - "\u001b[1m15/15\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 30ms/step - loss: 53927636992.0000 - val_loss: 48770617344.0000\n" - ] - }, - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 21, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "nn.fit(X_train, y_train, epochs=20, validation_data=(X_test, y_test))" ] }, { "cell_type": "code", - "execution_count": 22, + "execution_count": null, "id": "128b1ba9-55e9-4d78-9b31-d2a0da9bb165", "metadata": {}, "outputs": [], "source": [ - "nn.save('toto.keras')" + "nn.save(\"toto.keras\")" ] }, { "cell_type": "code", - "execution_count": 24, + "execution_count": null, "id": "9c820767-db55-48ba-8dd3-675d06fb5c3d", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 24, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "keras.saving.load_model('toto.keras')" + "keras.saving.load_model(\"toto.keras\")" ] }, { diff --git a/docs/examples/example2_student_admission.py b/docs/examples/example2_student_admission.py index 74f2b444..ab4766b6 100644 --- a/docs/examples/example2_student_admission.py +++ b/docs/examples/example2_student_admission.py @@ -82,7 +82,6 @@ """ import gurobipy as gp -import gurobipy_pandas as gppd import numpy as np import pandas as pd from sklearn.linear_model import LogisticRegression diff --git a/notebooks/Janos/Decision Tree.ipynb b/notebooks/Janos/Decision Tree.ipynb index d3deb6aa..1e34fee4 100644 --- a/notebooks/Janos/Decision Tree.ipynb +++ b/notebooks/Janos/Decision Tree.ipynb @@ -202,7 +202,7 @@ "metadata": {}, "outputs": [], "source": [ - "m.write('toto.lp')" + "m.write(\"toto.lp\")" ] }, { diff --git a/notebooks/Janos/Random Forest.ipynb b/notebooks/Janos/Random Forest.ipynb index 699fc93b..4ad0bd33 100644 --- a/notebooks/Janos/Random Forest.ipynb +++ b/notebooks/Janos/Random Forest.ipynb @@ -175,16 +175,6 @@ "We print the error.." ] }, - { - "cell_type": "code", - "execution_count": null, - "id": "7a746e47-4ff4-4595-82ab-a10cf5e4e597", - "metadata": {}, - "outputs": [], - "source": [ - "m.write(" - ] - }, { "cell_type": "code", "execution_count": null, @@ -279,7 +269,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": ".venv", "language": "python", "name": "python3" }, @@ -293,7 +283,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" }, "license": { "full_text": "# Copyright © 2023 Gurobi Optimization, LLC\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n# ==============================================================================" diff --git a/notebooks/adversarial/adversarial_logistic_regression.ipynb b/notebooks/adversarial/adversarial_logistic_regression.ipynb index e76405a6..9cc8c07d 100644 --- a/notebooks/adversarial/adversarial_logistic_regression.ipynb +++ b/notebooks/adversarial/adversarial_logistic_regression.ipynb @@ -34,8 +34,7 @@ "\n", "from sklearn.datasets import fetch_openml\n", "from sklearn.linear_model import LogisticRegression\n", - "from sklearn.pipeline import make_pipeline\n", - "from sklearn.preprocessing import StandardScaler" + "from sklearn.pipeline import make_pipeline" ] }, { @@ -66,7 +65,8 @@ "outputs": [], "source": [ "import sys\n", - "sys.path.append('../../src')" + "\n", + "sys.path.append(\"../../src\")" ] }, { @@ -77,8 +77,7 @@ }, "outputs": [], "source": [ - "from gurobi_ml import add_predictor_constr\n", - "from gurobi_ml.sklearn import logistic_regression" + "from gurobi_ml import add_predictor_constr" ] }, { @@ -98,7 +97,9 @@ "# Flatten and scale the data\n", "\n", "X = X.astype(np.float64) / 255.0\n", - "clf = LogisticRegression(C=50.0 / 500, penalty=\"l1\", solver=\"saga\", tol=0.1, random_state=4)\n", + "clf = LogisticRegression(\n", + " C=50.0 / 500, penalty=\"l1\", solver=\"saga\", tol=0.1, random_state=4\n", + ")\n", "pipeline = make_pipeline(clf)\n", "pipeline.fit(X, y)" ] @@ -122,7 +123,7 @@ }, "outputs": [], "source": [ - "ex_prob = clf.predict_proba(X[imageno:imageno+1, :])\n", + "ex_prob = clf.predict_proba(X[imageno : imageno + 1, :])\n", "sorted_labels = np.argsort(ex_prob)[0]\n", "right_label = sorted_labels[-1]\n", "wrong_label = sorted_labels[-2]" @@ -138,7 +139,7 @@ "source": [ "image = X[imageno, :]\n", "plt.imshow(image.reshape((28, 28)), cmap=\"gray\")\n", - "label = clf.predict(image.reshape(1,-1))\n", + "label = clf.predict(image.reshape(1, -1))\n", "print(f\"Solution is classified as {label}\")" ] }, @@ -165,7 +166,7 @@ "delta = 10\n", "\n", "x = m.addMVar(image.shape, lb=0.0, ub=1.0, name=\"x\")\n", - "y = m.addMVar(ex_prob.shape, lb=-float('inf'), name=\"y\")\n", + "y = m.addMVar(ex_prob.shape, lb=-float(\"inf\"), name=\"y\")\n", "\n", "abs_diff = m.addMVar(image.shape, lb=0, ub=1, name=\"abs_diff\")\n", "\n", @@ -177,7 +178,9 @@ "m.addConstr(abs_diff >= -x + image)\n", "m.addConstr(abs_diff.sum() <= delta)\n", "\n", - "pred_constr = add_predictor_constr(m, pipeline.steps[-1][1], x, y, epsilon=0, predict_function='predict_proba')\n", + "pred_constr = add_predictor_constr(\n", + " m, pipeline.steps[-1][1], x, y, epsilon=0, predict_function=\"predict_proba\"\n", + ")\n", "\n", "pred_constr.print_stats()" ] @@ -214,7 +217,7 @@ "outputs": [], "source": [ "plt.imshow(x.X.reshape((28, 28)), cmap=\"gray\")\n", - "label = pipeline.predict(x.X.reshape(1,-1))\n", + "label = pipeline.predict(x.X.reshape(1, -1))\n", "print(f\"Solution is classified as {label}\")" ] }, diff --git a/notebooks/adversarial/adversarial_pytorch.ipynb b/notebooks/adversarial/adversarial_pytorch.ipynb index d8283b96..26726cd0 100644 --- a/notebooks/adversarial/adversarial_pytorch.ipynb +++ b/notebooks/adversarial/adversarial_pytorch.ipynb @@ -158,7 +158,7 @@ "metadata": {}, "outputs": [], "source": [ - "ex_prob = nn_model.forward(x_train[imageno:imageno+1, :])[0]" + "ex_prob = nn_model.forward(x_train[imageno : imageno + 1, :])[0]" ] }, { diff --git a/notebooks/adversarial/adversarial_softmax.ipynb b/notebooks/adversarial/adversarial_softmax.ipynb index 2f5ec79d..b38838d9 100644 --- a/notebooks/adversarial/adversarial_softmax.ipynb +++ b/notebooks/adversarial/adversarial_softmax.ipynb @@ -33,8 +33,7 @@ "\n", "from sklearn.datasets import fetch_openml\n", "from sklearn.neural_network import MLPClassifier\n", - "from sklearn.pipeline import make_pipeline\n", - "from sklearn.preprocessing import StandardScaler" + "from sklearn.pipeline import make_pipeline" ] }, { @@ -65,7 +64,8 @@ "outputs": [], "source": [ "import sys\n", - "sys.path.append('../../src')" + "\n", + "sys.path.append(\"../../src\")" ] }, { @@ -76,9 +76,7 @@ }, "outputs": [], "source": [ - "from gurobi_ml import add_predictor_constr\n", - "from gurobi_ml.sklearn import mlpregressor\n", - "from gurobi_ml.modeling import softmax" + "from gurobi_ml import add_predictor_constr" ] }, { @@ -112,7 +110,7 @@ "outputs": [], "source": [ "X = X.astype(np.float64) / 255.0\n", - "clf = MLPClassifier([20,20])\n", + "clf = MLPClassifier([20, 20])\n", "pipeline = make_pipeline(clf)\n", "pipeline.fit(X, Y)" ] @@ -136,7 +134,7 @@ }, "outputs": [], "source": [ - "ex_prob = clf.predict_proba(X[imageno:imageno+1, :])\n", + "ex_prob = clf.predict_proba(X[imageno : imageno + 1, :])\n", "sorted_labels = np.argsort(ex_prob)[0]\n", "right_label = sorted_labels[-1]\n", "wrong_label = sorted_labels[-2]" @@ -171,7 +169,7 @@ "outputs": [], "source": [ "plt.imshow(image.reshape((28, 28)), cmap=\"gray\")\n", - "label = clf.predict(image.reshape(1,-1))\n", + "label = clf.predict(image.reshape(1, -1))\n", "print(f\"Solution is classified as {label}\")" ] }, @@ -198,7 +196,7 @@ "m.addConstr(abs_diff.sum() <= delta)\n", "\n", "# Gurobi ML magic\n", - "pred_constr = add_predictor_constr(m, clf, x, y, out_activation='softmax')\n", + "pred_constr = add_predictor_constr(m, clf, x, y, out_activation=\"softmax\")\n", "\n", "pred_constr.print_stats()" ] @@ -211,7 +209,7 @@ }, "outputs": [], "source": [ - "m.Params.OBBT=3\n", + "m.Params.OBBT = 3\n", "m.optimize()" ] }, @@ -224,7 +222,7 @@ "outputs": [], "source": [ "plt.imshow(x.X.reshape((28, 28)), cmap=\"gray\")\n", - "label = pipeline.predict(x.X.reshape(1,-1))\n", + "label = pipeline.predict(x.X.reshape(1, -1))\n", "print(f\"Solution is classified as {label}\")" ] }, diff --git a/src/gurobi_ml/keras/keras.py b/src/gurobi_ml/keras/keras.py index 4929aeae..edebba8c 100644 --- a/src/gurobi_ml/keras/keras.py +++ b/src/gurobi_ml/keras/keras.py @@ -112,7 +112,7 @@ def _mip_model(self, **kwargs): pass elif isinstance(step, (keras.layers.ReLU, keras.layers.Softmax)): layer = self._add_activation_layer( - _input, self.act_dict["relu"](), output, name=f"relu{i}", **kwargs + _input, self.act_dict["relu"], output, name=f"relu{i}", **kwargs ) _input = layer.output else: @@ -127,7 +127,7 @@ def _mip_model(self, **kwargs): _input, weights, bias, - self.act_dict[activation](), + self.act_dict[activation], output, name=f"dense{i}", **kwargs, diff --git a/src/gurobi_ml/modeling/softmax.py b/src/gurobi_ml/modeling/softmax.py index faf8e4f4..aaf1e384 100644 --- a/src/gurobi_ml/modeling/softmax.py +++ b/src/gurobi_ml/modeling/softmax.py @@ -165,10 +165,6 @@ def softmax( """Add the prediction constraints to Gurobi.""" gp_model: gp.Model = predictor_model.gp_model output: gp.MVar = predictor_model.output - try: - predict_function: str = predictor_model.predict_function - except AttributeError: - predict_function = "predict_proba" if "epsilon" in kwargs: epsilon = kwargs["epsilon"] @@ -190,7 +186,7 @@ def softmax( # Voila! gp_model.addConstr( - output == exponentials / denominator[:, np.newaxis], name=f"multlog" + output == exponentials / denominator[:, np.newaxis], name="multlog" ) else: # How boy that is tedious you don't want not to use Gurobi 12! diff --git a/src/gurobi_ml/sklearn/mlpregressor.py b/src/gurobi_ml/sklearn/mlpregressor.py index f5eb6ad3..bf0c96da 100644 --- a/src/gurobi_ml/sklearn/mlpregressor.py +++ b/src/gurobi_ml/sklearn/mlpregressor.py @@ -16,6 +16,7 @@ """Module for formulating a :external+sklearn:py:class:`sklearn.neural_network.MLPRegressor` in a :external+gurobi:py:class:`Model`. """ + from ..exceptions import NoModel from ..modeling.neuralnet import BaseNNConstr from .skgetter import SKClassifier, SKRegressor @@ -149,7 +150,7 @@ def _mip_model(self, **kwargs): neural_net, f"No implementation for activation function {neural_net.activation}", ) - activation = self.act_dict[neural_net.activation]() + activation = self.act_dict[neural_net.activation] input_vars = self._input output = None @@ -160,7 +161,7 @@ def _mip_model(self, **kwargs): # For last layer change activation if i == neural_net.n_layers_ - 2: - activation = self.act_dict[neural_net.out_activation_]() + activation = self.act_dict[neural_net.out_activation_] output = self._output if neural_net.out_activation_ in ("softmax", "logistic"): kwargs["predict_function"] = self.predict_function diff --git a/src/gurobi_ml/torch/sequential.py b/src/gurobi_ml/torch/sequential.py index 0d9113a3..46ff61ab 100644 --- a/src/gurobi_ml/torch/sequential.py +++ b/src/gurobi_ml/torch/sequential.py @@ -117,7 +117,7 @@ def _mip_model(self, **kwargs): _input, layer_weight, layer_bias, - self.act_dict["identity"](), + self.act_dict["identity"], output, name=f"linear_{i}", **kwargs, @@ -127,7 +127,7 @@ def _mip_model(self, **kwargs): activation = self.activations[type(step)] layer = self._add_activation_layer( _input, - self.act_dict[activation](), + self.act_dict[activation], output, name=f"{activation}_{i}", **kwargs, diff --git a/tests/test_keras/keras_cases.py b/tests/test_keras/keras_cases.py index dd36b851..d51b8fa3 100644 --- a/tests/test_keras/keras_cases.py +++ b/tests/test_keras/keras_cases.py @@ -1,4 +1,4 @@ -""" Cases to test for Keras +"""Cases to test for Keras We want to test networks with ReLU, Sigmoid and with or without SoftMax. diff --git a/tests/test_keras/test_keras_formulations.py b/tests/test_keras/test_keras_formulations.py index 2f528da5..a9231a62 100644 --- a/tests/test_keras/test_keras_formulations.py +++ b/tests/test_keras/test_keras_formulations.py @@ -5,6 +5,7 @@ from ..fixed_formulation import FixedRegressionModel from .keras_cases import HousingCases + VERBOSE = False diff --git a/tests/test_sklearn/test_sklearn_formulations.py b/tests/test_sklearn/test_sklearn_formulations.py index 647eeed1..9494411e 100644 --- a/tests/test_sklearn/test_sklearn_formulations.py +++ b/tests/test_sklearn/test_sklearn_formulations.py @@ -70,11 +70,7 @@ def test_iris_proba(self): data = datasets.load_iris() X = data.data - y = data.target - # Make it a simple classification - X = X[y != 2] - y = y[y != 2] cases = IrisBinaryCases() for regressor in cases: @@ -92,8 +88,6 @@ def test_iris_multi(self): data = datasets.load_iris() X = data.data - y = data.target - # Make it a simple classification cases = IrisMultiCases() @@ -106,11 +100,7 @@ def test_iris_clf(self): data = datasets.load_iris() X = data.data - y = data.target - # Make it a simple classification - X = X[y != 2] - y = y[y != 2] cases = IrisBinaryCases() for regressor in cases: @@ -124,11 +114,7 @@ def test_iris_pwl_args(self): data = datasets.load_iris() X = data.data - y = data.target - # Make it a simple classification - X = X[y != 2] - y = y[y != 2] cases = IrisBinaryCases() for regressor in cases: