Skip to content

Commit f75c9e6

Browse files
committed
Fix errors
1 parent 8893a6e commit f75c9e6

File tree

14 files changed

+60
-164
lines changed

14 files changed

+60
-164
lines changed

Generate_keras_test_network.ipynb

Lines changed: 21 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 12,
5+
"execution_count": null,
66
"id": "c8d57e80-9075-4d63-bc36-f9aaad08ea2f",
77
"metadata": {},
88
"outputs": [],
@@ -12,66 +12,55 @@
1212
},
1313
{
1414
"cell_type": "code",
15-
"execution_count": 13,
15+
"execution_count": null,
1616
"id": "90fa4efb-f9d5-40fb-8e4a-5e3ed1094740",
1717
"metadata": {},
18-
"outputs": [
19-
{
20-
"data": {
21-
"text/plain": [
22-
"'3.7.0'"
23-
]
24-
},
25-
"execution_count": 13,
26-
"metadata": {},
27-
"output_type": "execute_result"
28-
}
29-
],
18+
"outputs": [],
3019
"source": [
3120
"keras.__version__"
3221
]
3322
},
3423
{
3524
"cell_type": "code",
36-
"execution_count": 14,
25+
"execution_count": null,
3726
"id": "5d98d000-661e-4495-bef0-49c5eb180aff",
3827
"metadata": {},
3928
"outputs": [],
4029
"source": [
4130
"nn = keras.models.Sequential(\n",
4231
" [\n",
43-
" keras.layers.InputLayer((8,)),\n",
44-
" keras.layers.Dense(30, activation='relu'),\n",
45-
" keras.layers.Dense(1),\n",
32+
" keras.layers.InputLayer((8,)),\n",
33+
" keras.layers.Dense(30, activation=\"relu\"),\n",
34+
" keras.layers.Dense(1),\n",
4635
" ]\n",
4736
")"
4837
]
4938
},
5039
{
5140
"cell_type": "code",
52-
"execution_count": 15,
41+
"execution_count": null,
5342
"id": "ba3cf3ee-bd25-4180-95c0-2ff42d858a34",
5443
"metadata": {},
5544
"outputs": [],
5645
"source": [
57-
"nn.compile(loss='mean_squared_error', optimizer='adam')"
46+
"nn.compile(loss=\"mean_squared_error\", optimizer=\"adam\")"
5847
]
5948
},
6049
{
6150
"cell_type": "code",
62-
"execution_count": 16,
51+
"execution_count": null,
6352
"id": "247bd200-8026-4f08-8739-9aabb3c37e99",
6453
"metadata": {},
6554
"outputs": [],
6655
"source": [
67-
"(X_train, y_train), (X_test, y_test) = tf.keras.datasets.california_housing.load_data(\n",
56+
"(X_train, y_train), (X_test, y_test) = keras.datasets.california_housing.load_data(\n",
6857
" version=\"small\"\n",
69-
")\n"
58+
")"
7059
]
7160
},
7261
{
7362
"cell_type": "code",
74-
"execution_count": 18,
63+
"execution_count": null,
7564
"id": "a29325dd-1ab1-4cce-81c0-2528e892adb6",
7665
"metadata": {},
7766
"outputs": [],
@@ -81,7 +70,7 @@
8170
},
8271
{
8372
"cell_type": "code",
84-
"execution_count": 19,
73+
"execution_count": null,
8574
"id": "cbecbd91-e100-4568-9424-efd9e3b6d5fc",
8675
"metadata": {},
8776
"outputs": [],
@@ -93,100 +82,32 @@
9382
},
9483
{
9584
"cell_type": "code",
96-
"execution_count": 21,
85+
"execution_count": null,
9786
"id": "5656d2da-ee2d-4a8f-aef3-65876c20193b",
9887
"metadata": {},
99-
"outputs": [
100-
{
101-
"name": "stdout",
102-
"output_type": "stream",
103-
"text": [
104-
"Epoch 1/20\n",
105-
"\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",
106-
"Epoch 2/20\n",
107-
"\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",
108-
"Epoch 3/20\n",
109-
"\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",
110-
"Epoch 4/20\n",
111-
"\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",
112-
"Epoch 5/20\n",
113-
"\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",
114-
"Epoch 6/20\n",
115-
"\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",
116-
"Epoch 7/20\n",
117-
"\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",
118-
"Epoch 8/20\n",
119-
"\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",
120-
"Epoch 9/20\n",
121-
"\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",
122-
"Epoch 10/20\n",
123-
"\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",
124-
"Epoch 11/20\n",
125-
"\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",
126-
"Epoch 12/20\n",
127-
"\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",
128-
"Epoch 13/20\n",
129-
"\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",
130-
"Epoch 14/20\n",
131-
"\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",
132-
"Epoch 15/20\n",
133-
"\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",
134-
"Epoch 16/20\n",
135-
"\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",
136-
"Epoch 17/20\n",
137-
"\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",
138-
"Epoch 18/20\n",
139-
"\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",
140-
"Epoch 19/20\n",
141-
"\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",
142-
"Epoch 20/20\n",
143-
"\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"
144-
]
145-
},
146-
{
147-
"data": {
148-
"text/plain": [
149-
"<keras.src.callbacks.history.History at 0x7eb858fa50>"
150-
]
151-
},
152-
"execution_count": 21,
153-
"metadata": {},
154-
"output_type": "execute_result"
155-
}
156-
],
88+
"outputs": [],
15789
"source": [
15890
"nn.fit(X_train, y_train, epochs=20, validation_data=(X_test, y_test))"
15991
]
16092
},
16193
{
16294
"cell_type": "code",
163-
"execution_count": 22,
95+
"execution_count": null,
16496
"id": "128b1ba9-55e9-4d78-9b31-d2a0da9bb165",
16597
"metadata": {},
16698
"outputs": [],
16799
"source": [
168-
"nn.save('toto.keras')"
100+
"nn.save(\"toto.keras\")"
169101
]
170102
},
171103
{
172104
"cell_type": "code",
173-
"execution_count": 24,
105+
"execution_count": null,
174106
"id": "9c820767-db55-48ba-8dd3-675d06fb5c3d",
175107
"metadata": {},
176-
"outputs": [
177-
{
178-
"data": {
179-
"text/plain": [
180-
"<Sequential name=sequential_1, built=True>"
181-
]
182-
},
183-
"execution_count": 24,
184-
"metadata": {},
185-
"output_type": "execute_result"
186-
}
187-
],
108+
"outputs": [],
188109
"source": [
189-
"keras.saving.load_model('toto.keras')"
110+
"keras.saving.load_model(\"toto.keras\")"
190111
]
191112
},
192113
{

docs/examples/example2_student_admission.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
"""
8383

8484
import gurobipy as gp
85-
import gurobipy_pandas as gppd
85+
import gurobipy_pandas as gppd # noqa: F401
8686
import numpy as np
8787
import pandas as pd
8888
from sklearn.linear_model import LogisticRegression

notebooks/Janos/Decision Tree.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@
202202
"metadata": {},
203203
"outputs": [],
204204
"source": [
205-
"m.write('toto.lp')"
205+
"m.write(\"toto.lp\")"
206206
]
207207
},
208208
{

notebooks/Janos/Random Forest.ipynb

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,6 @@
175175
"We print the error.."
176176
]
177177
},
178-
{
179-
"cell_type": "code",
180-
"execution_count": null,
181-
"id": "7a746e47-4ff4-4595-82ab-a10cf5e4e597",
182-
"metadata": {},
183-
"outputs": [],
184-
"source": [
185-
"m.write("
186-
]
187-
},
188178
{
189179
"cell_type": "code",
190180
"execution_count": null,
@@ -279,7 +269,7 @@
279269
],
280270
"metadata": {
281271
"kernelspec": {
282-
"display_name": "Python 3 (ipykernel)",
272+
"display_name": ".venv",
283273
"language": "python",
284274
"name": "python3"
285275
},
@@ -293,7 +283,7 @@
293283
"name": "python",
294284
"nbconvert_exporter": "python",
295285
"pygments_lexer": "ipython3",
296-
"version": "3.11.10"
286+
"version": "3.11.11"
297287
},
298288
"license": {
299289
"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# =============================================================================="

notebooks/adversarial/adversarial_logistic_regression.ipynb

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@
3434
"\n",
3535
"from sklearn.datasets import fetch_openml\n",
3636
"from sklearn.linear_model import LogisticRegression\n",
37-
"from sklearn.pipeline import make_pipeline\n",
38-
"from sklearn.preprocessing import StandardScaler"
37+
"from sklearn.pipeline import make_pipeline"
3938
]
4039
},
4140
{
@@ -66,7 +65,8 @@
6665
"outputs": [],
6766
"source": [
6867
"import sys\n",
69-
"sys.path.append('../../src')"
68+
"\n",
69+
"sys.path.append(\"../../src\")"
7070
]
7171
},
7272
{
@@ -77,8 +77,7 @@
7777
},
7878
"outputs": [],
7979
"source": [
80-
"from gurobi_ml import add_predictor_constr\n",
81-
"from gurobi_ml.sklearn import logistic_regression"
80+
"from gurobi_ml import add_predictor_constr"
8281
]
8382
},
8483
{
@@ -98,7 +97,9 @@
9897
"# Flatten and scale the data\n",
9998
"\n",
10099
"X = X.astype(np.float64) / 255.0\n",
101-
"clf = LogisticRegression(C=50.0 / 500, penalty=\"l1\", solver=\"saga\", tol=0.1, random_state=4)\n",
100+
"clf = LogisticRegression(\n",
101+
" C=50.0 / 500, penalty=\"l1\", solver=\"saga\", tol=0.1, random_state=4\n",
102+
")\n",
102103
"pipeline = make_pipeline(clf)\n",
103104
"pipeline.fit(X, y)"
104105
]
@@ -122,7 +123,7 @@
122123
},
123124
"outputs": [],
124125
"source": [
125-
"ex_prob = clf.predict_proba(X[imageno:imageno+1, :])\n",
126+
"ex_prob = clf.predict_proba(X[imageno : imageno + 1, :])\n",
126127
"sorted_labels = np.argsort(ex_prob)[0]\n",
127128
"right_label = sorted_labels[-1]\n",
128129
"wrong_label = sorted_labels[-2]"
@@ -138,7 +139,7 @@
138139
"source": [
139140
"image = X[imageno, :]\n",
140141
"plt.imshow(image.reshape((28, 28)), cmap=\"gray\")\n",
141-
"label = clf.predict(image.reshape(1,-1))\n",
142+
"label = clf.predict(image.reshape(1, -1))\n",
142143
"print(f\"Solution is classified as {label}\")"
143144
]
144145
},
@@ -165,7 +166,7 @@
165166
"delta = 10\n",
166167
"\n",
167168
"x = m.addMVar(image.shape, lb=0.0, ub=1.0, name=\"x\")\n",
168-
"y = m.addMVar(ex_prob.shape, lb=-float('inf'), name=\"y\")\n",
169+
"y = m.addMVar(ex_prob.shape, lb=-float(\"inf\"), name=\"y\")\n",
169170
"\n",
170171
"abs_diff = m.addMVar(image.shape, lb=0, ub=1, name=\"abs_diff\")\n",
171172
"\n",
@@ -177,7 +178,9 @@
177178
"m.addConstr(abs_diff >= -x + image)\n",
178179
"m.addConstr(abs_diff.sum() <= delta)\n",
179180
"\n",
180-
"pred_constr = add_predictor_constr(m, pipeline.steps[-1][1], x, y, epsilon=0, predict_function='predict_proba')\n",
181+
"pred_constr = add_predictor_constr(\n",
182+
" m, pipeline.steps[-1][1], x, y, epsilon=0, predict_function=\"predict_proba\"\n",
183+
")\n",
181184
"\n",
182185
"pred_constr.print_stats()"
183186
]
@@ -214,7 +217,7 @@
214217
"outputs": [],
215218
"source": [
216219
"plt.imshow(x.X.reshape((28, 28)), cmap=\"gray\")\n",
217-
"label = pipeline.predict(x.X.reshape(1,-1))\n",
220+
"label = pipeline.predict(x.X.reshape(1, -1))\n",
218221
"print(f\"Solution is classified as {label}\")"
219222
]
220223
},

notebooks/adversarial/adversarial_pytorch.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@
158158
"metadata": {},
159159
"outputs": [],
160160
"source": [
161-
"ex_prob = nn_model.forward(x_train[imageno:imageno+1, :])[0]"
161+
"ex_prob = nn_model.forward(x_train[imageno : imageno + 1, :])[0]"
162162
]
163163
},
164164
{

0 commit comments

Comments
 (0)