|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": null, |
| 6 | + "id": "c8d57e80-9075-4d63-bc36-f9aaad08ea2f", |
| 7 | + "metadata": {}, |
| 8 | + "outputs": [], |
| 9 | + "source": [ |
| 10 | + "import tensorflow as tf" |
| 11 | + ] |
| 12 | + }, |
| 13 | + { |
| 14 | + "cell_type": "code", |
| 15 | + "execution_count": null, |
| 16 | + "id": "5d98d000-661e-4495-bef0-49c5eb180aff", |
| 17 | + "metadata": {}, |
| 18 | + "outputs": [], |
| 19 | + "source": [ |
| 20 | + "nn = tf.keras.models.Sequential(\n", |
| 21 | + " [\n", |
| 22 | + " tf.keras.layers.InputLayer((8,)),\n", |
| 23 | + " tf.keras.layers.Dense(30, activation='relu'),\n", |
| 24 | + " tf.keras.layers.Dense(1),\n", |
| 25 | + " ]\n", |
| 26 | + ")" |
| 27 | + ] |
| 28 | + }, |
| 29 | + { |
| 30 | + "cell_type": "code", |
| 31 | + "execution_count": null, |
| 32 | + "id": "ba3cf3ee-bd25-4180-95c0-2ff42d858a34", |
| 33 | + "metadata": {}, |
| 34 | + "outputs": [], |
| 35 | + "source": [ |
| 36 | + "nn.compile(loss='mean_squared_error', optimizer='adam')" |
| 37 | + ] |
| 38 | + }, |
| 39 | + { |
| 40 | + "cell_type": "code", |
| 41 | + "execution_count": null, |
| 42 | + "id": "247bd200-8026-4f08-8739-9aabb3c37e99", |
| 43 | + "metadata": {}, |
| 44 | + "outputs": [], |
| 45 | + "source": [ |
| 46 | + "(X_train, y_train), (X_test, y_test) = tf.keras.datasets.california_housing.load_data(\n", |
| 47 | + " version=\"large\"\n", |
| 48 | + ")\n" |
| 49 | + ] |
| 50 | + }, |
| 51 | + { |
| 52 | + "cell_type": "code", |
| 53 | + "execution_count": null, |
| 54 | + "id": "a29325dd-1ab1-4cce-81c0-2528e892adb6", |
| 55 | + "metadata": {}, |
| 56 | + "outputs": [], |
| 57 | + "source": [ |
| 58 | + "normalize = tf.keras.layers.Normalization(axis=-1)" |
| 59 | + ] |
| 60 | + }, |
| 61 | + { |
| 62 | + "cell_type": "code", |
| 63 | + "execution_count": null, |
| 64 | + "id": "cbecbd91-e100-4568-9424-efd9e3b6d5fc", |
| 65 | + "metadata": {}, |
| 66 | + "outputs": [], |
| 67 | + "source": [ |
| 68 | + "normalize.adapt(X_train)\n", |
| 69 | + "X_train = normalize(X_train)\n", |
| 70 | + "X_test = normalize(X_test)" |
| 71 | + ] |
| 72 | + }, |
| 73 | + { |
| 74 | + "cell_type": "code", |
| 75 | + "execution_count": null, |
| 76 | + "id": "5656d2da-ee2d-4a8f-aef3-65876c20193b", |
| 77 | + "metadata": {}, |
| 78 | + "outputs": [], |
| 79 | + "source": [ |
| 80 | + "nn.fit(X_train, y_train, epochs=100, validation_data=(X_test, y_test))" |
| 81 | + ] |
| 82 | + }, |
| 83 | + { |
| 84 | + "cell_type": "code", |
| 85 | + "execution_count": null, |
| 86 | + "id": "128b1ba9-55e9-4d78-9b31-d2a0da9bb165", |
| 87 | + "metadata": {}, |
| 88 | + "outputs": [], |
| 89 | + "source": [] |
| 90 | + } |
| 91 | + ], |
| 92 | + "metadata": { |
| 93 | + "kernelspec": { |
| 94 | + "display_name": "Python 3 (ipykernel)", |
| 95 | + "language": "python", |
| 96 | + "name": "python3" |
| 97 | + }, |
| 98 | + "language_info": { |
| 99 | + "codemirror_mode": { |
| 100 | + "name": "ipython", |
| 101 | + "version": 3 |
| 102 | + }, |
| 103 | + "file_extension": ".py", |
| 104 | + "mimetype": "text/x-python", |
| 105 | + "name": "python", |
| 106 | + "nbconvert_exporter": "python", |
| 107 | + "pygments_lexer": "ipython3", |
| 108 | + "version": "3.11.10" |
| 109 | + }, |
| 110 | + "license": { |
| 111 | + "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# ==============================================================================" |
| 112 | + } |
| 113 | + }, |
| 114 | + "nbformat": 4, |
| 115 | + "nbformat_minor": 5 |
| 116 | +} |
0 commit comments