1
0
This commit is contained in:
2025-01-25 22:33:14 +08:00
parent 81367980c1
commit f138818abc
14 changed files with 602 additions and 371 deletions

View File

@@ -2,20 +2,70 @@
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/Users/wolves/Downloads/project/python/AI-learning/lab\n"
]
}
],
"source": [
"import os\n",
"print(os.getcwd())"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"ExecuteTime": {
"end_time": "2025-01-20T09:22:08.756378Z",
"start_time": "2025-01-20T09:22:08.738301Z"
}
},
"outputs": [],
"source": [
"# 导库\n",
"from sklearn.datasets import make_classification\n",
"import tensorflow as tf\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from matplotlib.lines import Line2D\n",
"from matplotlib.colors import ListedColormap\n",
"from tensorflow.keras.layers import Dense\n",
"\n",
"# 使用GPU 6\n",
"from sklearn.metrics import accuracy_score\n",
"from tensorflow.keras.models import Sequential"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# 限制每个GPU使用4GB显存 通用gpu启用\n",
"gpus = tf.config.experimental.list_physical_devices('GPU')\n",
"if gpus:\n",
" try:\n",
" for gpu in gpus:\n",
" tf.config.experimental.set_virtual_device_configuration(\n",
" gpu,\n",
" [tf.config.experimental.VirtualDeviceConfiguration(memory_limit=4096)] # 限制每个GPU使用4GB显存\n",
" )\n",
" except RuntimeError as e:\n",
" print(e)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# 使用GPU 6 cuda启用\n",
"gpus = tf.config.experimental.list_physical_devices('GPU')\n",
"if gpus:\n",
" try:\n",
@@ -85,13 +135,14 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 17,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"模型运行在GPU设备: /device:GPU:0\n",
"Epoch 1/100\n"
]
},
@@ -99,287 +150,255 @@
"name": "stderr",
"output_type": "stream",
"text": [
"'+ptx85' is not a recognized feature for this target (ignoring feature)\n",
"'+ptx85' is not a recognized feature for this target (ignoring feature)\n",
"'+ptx85' is not a recognized feature for this target (ignoring feature)\n",
"'+ptx85' is not a recognized feature for this target (ignoring feature)\n",
"'+ptx85' is not a recognized feature for this target (ignoring feature)\n",
"'+ptx85' is not a recognized feature for this target (ignoring feature)\n",
"'+ptx85' is not a recognized feature for this target (ignoring feature)\n",
"'+ptx85' is not a recognized feature for this target (ignoring feature)\n",
"'+ptx85' is not a recognized feature for this target (ignoring feature)\n",
"'+ptx85' is not a recognized feature for this target (ignoring feature)\n",
"'+ptx85' is not a recognized feature for this target (ignoring feature)\n",
"'+ptx85' is not a recognized feature for this target (ignoring feature)\n",
"'+ptx85' is not a recognized feature for this target (ignoring feature)\n",
"'+ptx85' is not a recognized feature for this target (ignoring feature)\n",
"'+ptx85' is not a recognized feature for this target (ignoring feature)\n",
"'+ptx85' is not a recognized feature for this target (ignoring feature)\n",
"'+ptx85' is not a recognized feature for this target (ignoring feature)\n",
"'+ptx85' is not a recognized feature for this target (ignoring feature)\n",
"WARNING: All log messages before absl::InitializeLog() is called are written to STDERR\n",
"I0000 00:00:1736497931.531534 21216 service.cc:146] XLA service 0x7f49f4954650 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:\n",
"I0000 00:00:1736497931.531557 21216 service.cc:154] StreamExecutor device (0): NVIDIA A800 80GB PCIe, Compute Capability 8.0\n",
"2025-01-10 08:32:11.540274: I tensorflow/compiler/mlir/tensorflow/utils/dump_mlir_util.cc:268] disabling MLIR crash reproducer, set env var `MLIR_CRASH_REPRODUCER_DIRECTORY` to enable.\n",
"2025-01-10 08:32:11.571961: I external/local_xla/xla/stream_executor/cuda/cuda_dnn.cc:531] Loaded cuDNN version 90600\n",
"'+ptx85' is not a recognized feature for this target (ignoring feature)\n",
"'+ptx85' is not a recognized feature for this target (ignoring feature)\n",
"'+ptx85' is not a recognized feature for this target (ignoring feature)\n",
"I0000 00:00:1736497931.646086 21216 device_compiler.h:188] Compiled cluster using XLA! This line is logged at most once for the lifetime of the process.\n",
"'+ptx85' is not a recognized feature for this target (ignoring feature)\n",
"'+ptx85' is not a recognized feature for this target (ignoring feature)\n",
"'+ptx85' is not a recognized feature for this target (ignoring feature)\n"
"2025-01-20 17:58:23.192972: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:305] Could not identify NUMA node of platform GPU ID 0, defaulting to 0. Your kernel may not have been built with NUMA support.\n",
"2025-01-20 17:58:23.192998: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:271] Created TensorFlow device (/device:GPU:0 with 0 MB memory) -> physical PluggableDevice (device: 0, name: METAL, pci bus id: <undefined>)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"2/2 [==============================] - 2s 10ms/step - loss: 0.7364\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 103ms/step - loss: 60.6063\n",
"Epoch 2/100\n",
"2/2 [==============================] - 0s 5ms/step - loss: 0.7210\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 24ms/step - loss: 28.2659\n",
"Epoch 3/100\n",
"2/2 [==============================] - 0s 6ms/step - loss: 0.7066\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 26ms/step - loss: 1.4893\n",
"Epoch 4/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.6929\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 25ms/step - loss: 4.0465\n",
"Epoch 5/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.6786\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 27ms/step - loss: 6.5380\n",
"Epoch 6/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.6668\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 24ms/step - loss: 8.9314\n",
"Epoch 7/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.6531\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 25ms/step - loss: 8.9564\n",
"Epoch 8/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.6411\n",
"Epoch 9/100\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"'+ptx85' is not a recognized feature for this target (ignoring feature)\n",
"'+ptx85' is not a recognized feature for this target (ignoring feature)\n",
"'+ptx85' is not a recognized feature for this target (ignoring feature)\n",
"'+ptx85' is not a recognized feature for this target (ignoring feature)\n",
"'+ptx85' is not a recognized feature for this target (ignoring feature)\n",
"'+ptx85' is not a recognized feature for this target (ignoring feature)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"2/2 [==============================] - 0s 7ms/step - loss: 0.6245\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 26ms/step - loss: 10.6051\n",
"Epoch 9/100\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 26ms/step - loss: 12.0071\n",
"Epoch 10/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.6015\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 27ms/step - loss: 10.6521\n",
"Epoch 11/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.5786\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 26ms/step - loss: 14.1705\n",
"Epoch 12/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.5240\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 24ms/step - loss: 13.1806\n",
"Epoch 13/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.5058\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 23ms/step - loss: 12.1059\n",
"Epoch 14/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4971\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 23ms/step - loss: 13.4850\n",
"Epoch 15/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4868\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 23ms/step - loss: 12.3003\n",
"Epoch 16/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4798\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 26ms/step - loss: 11.7990\n",
"Epoch 17/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4722\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 27ms/step - loss: 10.3683\n",
"Epoch 18/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4654\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 27ms/step - loss: 9.7598 \n",
"Epoch 19/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4600\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 27ms/step - loss: 10.2508\n",
"Epoch 20/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4560\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 26ms/step - loss: 8.2063\n",
"Epoch 21/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4506\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 24ms/step - loss: 6.3501\n",
"Epoch 22/100\n",
"2/2 [==============================] - 0s 6ms/step - loss: 0.4460\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 26ms/step - loss: 6.1186\n",
"Epoch 23/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4432\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 27ms/step - loss: 4.8664\n",
"Epoch 24/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4404\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 26ms/step - loss: 4.0431\n",
"Epoch 25/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4380\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 24ms/step - loss: 3.5386\n",
"Epoch 26/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4349\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 25ms/step - loss: 2.7600\n",
"Epoch 27/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4335\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 24ms/step - loss: 1.3724\n",
"Epoch 28/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4313\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 24ms/step - loss: 0.5045\n",
"Epoch 29/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4301\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 22ms/step - loss: 1.9855\n",
"Epoch 30/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4293\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 25ms/step - loss: 1.0879\n",
"Epoch 31/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4278\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 25ms/step - loss: 0.6851\n",
"Epoch 32/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4270\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 27ms/step - loss: 1.2047\n",
"Epoch 33/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4259\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 24ms/step - loss: 1.5541\n",
"Epoch 34/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4257\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 24ms/step - loss: 1.2758\n",
"Epoch 35/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4249\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 24ms/step - loss: 1.3003\n",
"Epoch 36/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4245\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 26ms/step - loss: 0.8837\n",
"Epoch 37/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4247\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 24ms/step - loss: 0.5647\n",
"Epoch 38/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4239\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 26ms/step - loss: 0.6855\n",
"Epoch 39/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4238\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 26ms/step - loss: 0.5609\n",
"Epoch 40/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4238\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 27ms/step - loss: 0.4828\n",
"Epoch 41/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4232\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 29ms/step - loss: 0.6055\n",
"Epoch 42/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4232\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 65ms/step - loss: 0.5680\n",
"Epoch 43/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4232\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 22ms/step - loss: 0.3890\n",
"Epoch 44/100\n",
"2/2 [==============================] - 0s 8ms/step - loss: 0.4229\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 23ms/step - loss: 0.4543\n",
"Epoch 45/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4229\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 24ms/step - loss: 0.4878\n",
"Epoch 46/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4230\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 27ms/step - loss: 0.4287\n",
"Epoch 47/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4229\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 23ms/step - loss: 0.4933\n",
"Epoch 48/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4228\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 27ms/step - loss: 0.5080\n",
"Epoch 49/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4228\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 26ms/step - loss: 0.4485\n",
"Epoch 50/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4228\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 24ms/step - loss: 0.4195\n",
"Epoch 51/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4228\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 25ms/step - loss: 0.4215\n",
"Epoch 52/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4228\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 24ms/step - loss: 0.4477\n",
"Epoch 53/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4227\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 32ms/step - loss: 0.4759\n",
"Epoch 54/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4227\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 26ms/step - loss: 0.4077\n",
"Epoch 55/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4227\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 24ms/step - loss: 0.4073\n",
"Epoch 56/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4227\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 24ms/step - loss: 0.3936\n",
"Epoch 57/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4228\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 25ms/step - loss: 0.4006\n",
"Epoch 58/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4227\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 25ms/step - loss: 0.4254\n",
"Epoch 59/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4228\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 24ms/step - loss: 0.4196\n",
"Epoch 60/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4228\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 23ms/step - loss: 0.4221\n",
"Epoch 61/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4227\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 23ms/step - loss: 0.4271\n",
"Epoch 62/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4227\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 26ms/step - loss: 0.4239\n",
"Epoch 63/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4227\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 25ms/step - loss: 0.3905\n",
"Epoch 64/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4227\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 26ms/step - loss: 0.4415\n",
"Epoch 65/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4227\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 66ms/step - loss: 0.4230\n",
"Epoch 66/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4228\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 22ms/step - loss: 0.3950\n",
"Epoch 67/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4227\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 23ms/step - loss: 0.4236\n",
"Epoch 68/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4227\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 26ms/step - loss: 0.4291\n",
"Epoch 69/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4227\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 26ms/step - loss: 0.4066\n",
"Epoch 70/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4227\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 30ms/step - loss: 0.4228\n",
"Epoch 71/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4227\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 23ms/step - loss: 0.3788\n",
"Epoch 72/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4228\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 23ms/step - loss: 0.4248\n",
"Epoch 73/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4227\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 25ms/step - loss: 0.4265\n",
"Epoch 74/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4227\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 25ms/step - loss: 0.4165\n",
"Epoch 75/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4228\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 26ms/step - loss: 0.4262\n",
"Epoch 76/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4227\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 25ms/step - loss: 0.4238\n",
"Epoch 77/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4227\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 26ms/step - loss: 0.4055\n",
"Epoch 78/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4227\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 25ms/step - loss: 0.4483\n",
"Epoch 79/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4227\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 26ms/step - loss: 0.4379\n",
"Epoch 80/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4227\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 25ms/step - loss: 0.4697\n",
"Epoch 81/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4228\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 25ms/step - loss: 0.4096\n",
"Epoch 82/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4227\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 23ms/step - loss: 0.4069\n",
"Epoch 83/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4227\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 24ms/step - loss: 0.4518\n",
"Epoch 84/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4228\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 24ms/step - loss: 0.4145\n",
"Epoch 85/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4227\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 23ms/step - loss: 0.3853\n",
"Epoch 86/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4227\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 60ms/step - loss: 0.4064\n",
"Epoch 87/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4227\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 23ms/step - loss: 0.4533\n",
"Epoch 88/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4228\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 23ms/step - loss: 0.4798\n",
"Epoch 89/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4227\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 23ms/step - loss: 0.4093\n",
"Epoch 90/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4227\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 22ms/step - loss: 0.4176\n",
"Epoch 91/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4227\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 22ms/step - loss: 0.4351\n",
"Epoch 92/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4227\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 26ms/step - loss: 0.4422\n",
"Epoch 93/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4227\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 26ms/step - loss: 0.4550\n",
"Epoch 94/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4228\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 24ms/step - loss: 0.4387\n",
"Epoch 95/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4227\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 24ms/step - loss: 0.4847\n",
"Epoch 96/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4227\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 25ms/step - loss: 0.4777\n",
"Epoch 97/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4228\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 25ms/step - loss: 0.4309\n",
"Epoch 98/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4227\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 25ms/step - loss: 0.4221\n",
"Epoch 99/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4227\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 23ms/step - loss: 0.4159\n",
"Epoch 100/100\n",
"2/2 [==============================] - 0s 7ms/step - loss: 0.4227\n",
"2/2 [==============================] - 0s 2ms/step\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 22ms/step - loss: 0.3821\n",
"\u001b[1m2/2\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 34ms/step\n",
"模型的精准度: 0.85\n"
]
}
],
"source": [
"# 输出模型当时是在什么设备上运行\n",
"device_name = tf.test.gpu_device_name()\n",
"if device_name:\n",
" print(f\"模型运行在GPU设备: {device_name}\")\n",
"else:\n",
" print(\"模型运行在CPU设备\")\n",
"\n",
"# 写法1\n",
"# model = tf.keras.Sequential()\n",
"# layer_1 = Dense(units=3,activation='sigmoid')\n",
"# layer_2 = Dense(units=1,activation='sigmoid')\n",
"# model.add(layer_1)\n",
"# model.add(layer_2)\n",
"\n",
"#写法2\n",
"# layer_1 = Dense(units=3,activation='sigmoid')\n",
"# layer_2 = Dense(units=1,activation='sigmoid')\n",
"# model = Sequential([layer_1, layer_2])\n",
"\n",
"# 写法3\n",
"model = Sequential([Dense(units=10,activation='relu'),\n",
" Dense(units=5,activation='relu'),\n",
" Dense(units=1,activation='sigmoid')])\n",
"\n",
"model = tf.keras.Sequential()\n",
"layer_1 = Dense(units=3,activation='sigmoid')\n",
"layer_2 = Dense(units=1,activation='sigmoid')\n",
"model.add(layer_1)\n",
"model.add(layer_2)\n",
"model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.01),loss='binary_crossentropy')\n",
"model.fit(x,y,epochs=100)\n",
"a = model.predict(x)\n",
"\n",
"# 计算并输出模型的精准度\n",
"from sklearn.metrics import accuracy_score\n",
"\n",
"# 将预测结果转换为二进制标签\n",
"predicted_labels = (a > 0.5).astype(int)\n",
"\n",
"# 计算精准度\n",
"accuracy = accuracy_score(y, predicted_labels)\n",
"print(f\"模型的精准度: {accuracy:.2f}\")\n",
"\n",
"\n"
"print(f\"模型的精准度: {accuracy:.2f}\")"
]
}
],
@@ -388,6 +407,18 @@
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.16"
}
},
"nbformat": 4,