Files
PSI/LAB3.ipynb

633 lines
24 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"id": "e240313e75a92965",
"metadata": {},
"source": "# Laboratorium 3"
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2026-11-02T15:48:05.431744233Z",
"start_time": "2026-11-02T15:48:05.207672302Z"
}
},
"cell_type": "code",
"source": [
"from tensorflow import keras\n",
"from keras.models import Sequential\n",
"from keras.layers import Dense\n",
"from keras.optimizers import SGD\n",
"import numpy as np\n",
"import struct"
],
"id": "4d18fbc40747d5a3",
"outputs": [],
"execution_count": 159
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Zadanie 1",
"id": "b70f4ee5d79e60"
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2026-11-02T15:48:05.526470433Z",
"start_time": "2026-11-02T15:48:05.438979772Z"
}
},
"cell_type": "code",
"source": [
"x = np.array([[0.5, 0.1, 0.2, 0.8], [0.75, 0.3, 0.1, 0.9], [0.1, 0.7, 0.6, 0.2]])\n",
"\n",
"Wh = np.array([\n",
" [0.1, 0.1, -0.3],\n",
" [0.1, 0.2, 0.0],\n",
" [0.0, 0.7, 0.1],\n",
" [0.2, 0.4, 0.0],\n",
" [-0.3, 0.5, 0.1]\n",
"])\n",
"\n",
"Wy = np.array([\n",
" [0.7, 0.9, -0.4, 0.8, 0.1],\n",
" [0.8, 0.5, 0.3, 0.1, 0.0],\n",
" [-0.3, 0.9, 0.3, 0.1, -0.2]\n",
"])\n",
"\n",
"\n",
"def ReLu(x):\n",
" return np.maximum(x, 0)\n",
"\n",
"\n",
"def deep_neural_network(input, weights_h, weights_y):\n",
" layer_hidden_1 = np.dot(weights_h, input)\n",
" layer_hidden_1_r = ReLu(layer_hidden_1)\n",
" layer_output = np.dot(weights_y, layer_hidden_1_r)\n",
" return layer_hidden_1, layer_hidden_1_r, layer_output\n",
"\n",
"\n",
"layer_hidden_1, layer_hidden_1_r, layer_output = deep_neural_network(x, Wh, Wy)\n",
"\n",
"print(layer_output)\n"
],
"id": "1fe1f57f2e5d30a8",
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[0.376 0.082 0.053 0.49 ]\n",
" [0.3765 0.133 0.067 0.465 ]\n",
" [0.305 0.123 0.073 0.402 ]]\n"
]
}
],
"execution_count": 160
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Zadanie 2",
"id": "c04a058b137dfe88"
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2026-11-02T15:48:05.564390548Z",
"start_time": "2026-11-02T15:48:05.533869120Z"
}
},
"cell_type": "code",
"source": [
"goal = np.array([\n",
" [0.1, 0.5, 0.1, 0.7],\n",
" [1.0, 0.2, 0.3, 0.6],\n",
" [0.1, -0.5, 0.2, 0.2],\n",
"])\n",
"\n",
"alpha = 0.01\n",
"epochs = 50\n",
"\n",
"\n",
"def ReLu_deriv(x):\n",
" return np.where(x > 0, 1, 0)\n",
"\n",
"\n",
"def supervised_learning(input, weights_h, weights_y, goal, alpha, epochs):\n",
" num_neurons = goal.shape[0]\n",
" num_series = input.shape[1]\n",
" for i in range(epochs):\n",
" for j in range(num_series):\n",
" series_input = input[:, j:j + 1]\n",
" series_goal = goal[:, j:j + 1]\n",
" layer_hidden_1, layer_hidden_1_r, layer_output = deep_neural_network(series_input, weights_h, weights_y)\n",
"\n",
" layer_output_delta = (2 / num_neurons) * (layer_output - series_goal)\n",
"\n",
" layer_hidden_delta = np.dot(weights_y.T, layer_output_delta)\n",
" layer_hidden_delta = layer_hidden_delta * ReLu_deriv(layer_hidden_1)\n",
"\n",
" layer_output_weight_delta = np.dot(layer_output_delta, layer_hidden_1_r.T)\n",
" layer_hidden_weight_delta = np.dot(layer_hidden_delta, series_input.T)\n",
"\n",
" weights_h = weights_h - alpha * layer_hidden_weight_delta\n",
" weights_y = weights_y - alpha * layer_output_weight_delta\n",
" if (i == epochs - 1):\n",
" print(f\"\\nSeria {j + 1}:\")\n",
" print(np.round(layer_output, 6))\n",
"\n",
" return layer_output\n",
"\n",
"\n",
"output = supervised_learning(x, Wh, Wy, goal, alpha, epochs)\n"
],
"id": "d13e053086fe80f6",
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Seria 1:\n",
"[[0.442756]\n",
" [0.565494]\n",
" [0.157309]]\n",
"\n",
"Seria 2:\n",
"[[0.140418]\n",
" [0.186105]\n",
" [0.063895]]\n",
"\n",
"Seria 3:\n",
"[[0.105594]\n",
" [0.093659]\n",
" [0.045049]]\n",
"\n",
"Seria 4:\n",
"[[0.584537]\n",
" [0.711427]\n",
" [0.216373]]\n"
]
}
],
"execution_count": 161
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Zadanie 3",
"id": "111fd4dd04394153"
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2026-11-02T15:48:05.644432142Z",
"start_time": "2026-11-02T15:48:05.586047916Z"
}
},
"cell_type": "code",
"source": [
"def sigmoid(x):\n",
" x = np.clip(x, -500, 500)\n",
" return 1 / (1 + np.exp(-x))\n",
"\n",
"\n",
"def sigmoid_deriv(x):\n",
" return x * (1 - x)\n",
"\n",
"\n",
"class NeuralNewtork:\n",
" def __init__(self, n, a=0.01):\n",
" self.num_neurons = n\n",
" self.alpha = a\n",
" self.layers = {\n",
" 'weights': [],\n",
" 'activation_function': [],\n",
" 'derivative_function': [],\n",
" }\n",
"\n",
" def add_layer(self, n, activation_func):\n",
" weights = np.random.uniform(-1, 1, (n, self.num_neurons))\n",
" self.layers['weights'].append(weights)\n",
" self.num_neurons = n\n",
" if activation_func is not None:\n",
" self.layers['activation_function'].append(activation_func)\n",
" if activation_func == 'sigmoid':\n",
" self.layers['derivative_function'].append(sigmoid_deriv)\n",
" else:\n",
" self.layers['derivative_function'].append(ReLu_deriv)\n",
" else:\n",
" self.layers['activation_function'].append(None)\n",
" self.layers['derivative_function'].append(None)\n",
"\n",
" def forward_propagation(self, input):\n",
" activation = []\n",
" raw_output = []\n",
"\n",
" current_input = input\n",
" for i in range(len(self.layers['weights'])):\n",
" z = np.dot(self.layers['weights'][i], current_input)\n",
" raw_output.append(z)\n",
"\n",
" a = self.layers['activation_function'][i](z)\n",
" activation.append(a)\n",
" current_input = a\n",
"\n",
" return activation, raw_output\n",
"\n",
" def back_propagation(self, activation, input, raw_output, expected_output):\n",
" N = expected_output.shape[0]\n",
" layer_output_delta = (2 * 1 / N) * (activation[-1] - expected_output)\n",
"\n",
" layer_hidden_delta = np.dot(self.layers['weights'][-1].T, layer_output_delta)\n",
"\n",
" layer_output_weight_delta = np.dot(layer_output_delta, activation[-2].T)\n",
" self.layers['weights'][-1] = self.layers['weights'][-1] - self.alpha * layer_output_weight_delta\n",
"\n",
" for i in reversed(range(len(self.layers['weights']) - 1)):\n",
" layer_hidden_delta = layer_hidden_delta * self.layers['derivative_function'][i](raw_output[i])\n",
"\n",
" wejscie_lub_aktywacja = activation[i - 1] if i > 0 else input\n",
" layer_hidden_weight_delta = np.dot(layer_hidden_delta, wejscie_lub_aktywacja.T)\n",
"\n",
" self.layers['weights'][i] = self.layers['weights'][i] - self.alpha * layer_hidden_weight_delta\n",
"\n",
" def fit(self, input, expected_output):\n",
" input_data = (input.copy()).reshape(1, -1).T\n",
" activation, raw_output = self.forward_propagation(input_data)\n",
" self.back_propagation(activation, input_data, raw_output, expected_output)\n",
"\n",
" def predict(self, input):\n",
" input_data = (input.copy()).reshape(-1, 1)\n",
" activation, _ = self.forward_propagation(input_data)\n",
" return activation[-1]\n",
"\n",
"def load_mnist_images(filename):\n",
" with open(filename, 'rb') as f:\n",
" magic, num_images, rows, cols = struct.unpack('>IIII', f.read(16))\n",
" image_data = np.frombuffer(f.read(), dtype=np.uint8)\n",
" images = image_data.reshape(num_images, rows * cols).astype(np.float32) / 255.0\n",
" return images\n",
"\n",
"\n",
"def load_mnist_labels(filename):\n",
" with open(filename, 'rb') as f:\n",
" magic, num_labels = struct.unpack('>II', f.read(8))\n",
" labels = np.frombuffer(f.read(), dtype=np.uint8)\n",
" return labels\n",
"\n",
"\n",
"def to_one_hot(label, num_classes=10):\n",
" one_hot = np.zeros((num_classes, 1))\n",
" one_hot[label] = 1.0\n",
" return one_hot"
],
"id": "49b96a3eca9ceae9",
"outputs": [],
"execution_count": 162
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2026-11-02T15:48:28.235953110Z",
"start_time": "2026-11-02T15:48:05.646551099Z"
}
},
"cell_type": "code",
"source": [
"nn = NeuralNewtork(784)\n",
"nn.add_layer(40, ReLu)\n",
"nn.add_layer(10, ReLu)\n",
"\n",
"train_image = load_mnist_images('train-images.idx3-ubyte')\n",
"train_image_labels = load_mnist_labels('train-labels.idx1-ubyte')\n",
"\n",
"test_image = load_mnist_images('t10k-images.idx3-ubyte')\n",
"test_image_labels = load_mnist_labels('t10k-labels.idx1-ubyte')\n",
"\n",
"epochs = 6\n",
"\n",
"print(\"Rozpoczynam proces uczenia sieci...\")\n",
"for epoch in range(epochs):\n",
" correct_train = 0\n",
"\n",
" for i in range(len(train_image)):\n",
" x = train_image[i].reshape(-1, 1)\n",
" label = train_image_labels[i]\n",
" expected = to_one_hot(label)\n",
"\n",
" nn.fit(x, expected)\n",
"\n",
" activation = nn.predict(x)\n",
" predicted_label = np.argmax(activation)\n",
" if predicted_label == label:\n",
" correct_train += 1\n",
"\n",
" train_accuracy = correct_train / len(train_image) * 100\n",
" print(f\"Epoka {epoch + 1}/{epochs} zakończona. Skuteczność treningowa: {train_accuracy:.2f}%\")\n"
],
"id": "b2ee263a039e016e",
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Rozpoczynam proces uczenia sieci...\n",
"Epoka 1/6 zakończona. Skuteczność treningowa: 61.03%\n",
"Epoka 2/6 zakończona. Skuteczność treningowa: 77.58%\n",
"Epoka 3/6 zakończona. Skuteczność treningowa: 83.84%\n",
"Epoka 4/6 zakończona. Skuteczność treningowa: 86.83%\n",
"Epoka 5/6 zakończona. Skuteczność treningowa: 88.48%\n",
"Epoka 6/6 zakończona. Skuteczność treningowa: 89.54%\n"
]
}
],
"execution_count": 163
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2026-11-02T15:48:28.366459094Z",
"start_time": "2026-11-02T15:48:28.238764489Z"
}
},
"cell_type": "code",
"source": [
"print(\"\\n--- TESTOWANIE SIECI (Zbiór testowy t10k) ---\")\n",
"correct_test = 0\n",
"\n",
"for i in range(len(test_image)):\n",
" x = test_image[i].reshape(-1, 1)\n",
" label = test_image_labels[i]\n",
"\n",
" activation = nn.predict(x)\n",
" predicted_label = np.argmax(activation)\n",
"\n",
" if predicted_label == label:\n",
" correct_test += 1\n",
"\n",
"test_accuracy = correct_test / len(test_image) * 100\n",
"print(f\"Skuteczność testowa modelu: {test_accuracy:.2f}%\")"
],
"id": "7b709ff408ad9843",
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"--- TESTOWANIE SIECI (Zbiór testowy t10k) ---\n",
"Skuteczność testowa modelu: 82.61%\n"
]
}
],
"execution_count": 164
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Zadanie 4",
"id": "a5a0fbb71d562dba"
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2026-11-02T15:48:28.456012551Z",
"start_time": "2026-11-02T15:48:28.374327966Z"
}
},
"cell_type": "code",
"source": [
"data = np.loadtxt('training_colors.txt')\n",
"\n",
"input = data[:, :3]\n",
"input_info = data[:, 3]\n",
"\n",
"goal = np.zeros((1, 4))\n",
"\n",
"color_map = {\n",
" 1: [1.0, 0.0, 0.0, 0.0], # Czerwony\n",
" 2: [0.0, 1.0, 0.0, 0.0], # Zielony\n",
" 3: [0.0, 0.0, 1.0, 0.0], # Niebieski\n",
" 4: [0.0, 0.0, 0.0, 1.0], # Żółty\n",
"}\n",
"\n",
"goal_list = [color_map[int(label)] for label in input_info]\n",
"goal = np.array(goal_list)\n",
"\n",
"nn = NeuralNewtork(3)\n",
"nn.add_layer(16, ReLu)\n",
"nn.add_layer(4, ReLu)\n",
"\n",
"epochs = 10\n",
"\n",
"print(\"Rozpoczynam proces uczenia sieci...\")\n",
"for epoch in range(epochs):\n",
" correct_train = 0\n",
"\n",
" for i in range(len(data)):\n",
" x = input[i].reshape(-1, 1)\n",
"\n",
" expected = goal[i].reshape(-1, 1)\n",
"\n",
" nn.fit(x, expected)\n",
"\n",
" activation = nn.predict(x)\n",
" predicted_label = np.argmax(activation)\n",
"\n",
" if predicted_label == int(input_info[i]) - 1:\n",
" correct_train += 1\n",
" train_accuracy = correct_train / len(data) * 100\n",
" print(f\"Epoka {epoch + 1}/{epochs} zakończona. Skuteczność treningowa: {train_accuracy:.2f}%\")\n"
],
"id": "1b869f3b7546661b",
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Rozpoczynam proces uczenia sieci...\n",
"Epoka 1/10 zakończona. Skuteczność treningowa: 50.46%\n",
"Epoka 2/10 zakończona. Skuteczność treningowa: 90.83%\n",
"Epoka 3/10 zakończona. Skuteczność treningowa: 100.00%\n",
"Epoka 4/10 zakończona. Skuteczność treningowa: 100.00%\n",
"Epoka 5/10 zakończona. Skuteczność treningowa: 100.00%\n",
"Epoka 6/10 zakończona. Skuteczność treningowa: 100.00%\n",
"Epoka 7/10 zakończona. Skuteczność treningowa: 100.00%\n",
"Epoka 8/10 zakończona. Skuteczność treningowa: 100.00%\n",
"Epoka 9/10 zakończona. Skuteczność treningowa: 100.00%\n",
"Epoka 10/10 zakończona. Skuteczność treningowa: 100.00%\n"
]
}
],
"execution_count": 165
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2026-11-02T15:48:28.512064093Z",
"start_time": "2026-11-02T15:48:28.457851611Z"
}
},
"cell_type": "code",
"source": [
"test_data = np.loadtxt('test_colors.txt')\n",
"\n",
"input_test = test_data[:, :3]\n",
"input_test_info = (test_data[:, 3] - 1)\n",
"\n",
"print(\"\\n--- TESTOWANIE SIECI (Zbiór testowy t10k) ---\")\n",
"correct_test = 0\n",
"\n",
"for i in range(len(test_data)):\n",
" x = input_test[i].reshape(-1, 1)\n",
"\n",
" activation = nn.predict(x)\n",
" predicted_label = np.argmax(activation)\n",
"\n",
" if predicted_label == int(input_test_info[i]):\n",
" correct_test += 1\n",
"\n",
"test_accuracy = correct_test / len(test_data) * 100\n",
"print(f\"Skuteczność testowa modelu: {test_accuracy:.2f}%\")"
],
"id": "6074d03eb64c3496",
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"--- TESTOWANIE SIECI (Zbiór testowy t10k) ---\n",
"Skuteczność testowa modelu: 100.00%\n"
]
}
],
"execution_count": 166
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Zadanie 5\n",
"id": "133f30d616b9b9c2"
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2026-11-02T15:48:31.171962142Z",
"start_time": "2026-11-02T15:48:28.515088448Z"
}
},
"cell_type": "code",
"source": [
"y_test = keras.utils.to_categorical(input_test_info, num_classes=4)\n",
"\n",
"model = Sequential()\n",
"\n",
"model.add(keras.Input(shape=(3,)))\n",
"model.add(Dense(16, use_bias=False, activation='relu'))\n",
"model.add(Dense(4, use_bias=False))\n",
"opt = SGD(learning_rate=0.01)\n",
"model.compile(opt, loss='mse', metrics=['accuracy'])\n",
"\n",
"model.fit(\n",
" input,\n",
" goal,\n",
" epochs=25,\n",
" batch_size=5,\n",
" validation_data=(input_test, y_test),\n",
" verbose=1\n",
")\n",
"test_loss, test_accuracy = model.evaluate(input_test, y_test, verbose=0)\n",
"print(f\"\\nSkuteczność modelu na zbiorze testowym: {test_accuracy * 100:.2f}%\")"
],
"id": "73ab306f4a4cdba6",
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Epoch 1/25\n",
"\u001B[1m22/22\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m0s\u001B[0m 7ms/step - accuracy: 0.2294 - loss: 0.2698 - val_accuracy: 0.2231 - val_loss: 0.2566\n",
"Epoch 2/25\n",
"\u001B[1m22/22\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m0s\u001B[0m 4ms/step - accuracy: 0.2294 - loss: 0.2477 - val_accuracy: 0.2615 - val_loss: 0.2374\n",
"Epoch 3/25\n",
"\u001B[1m22/22\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m0s\u001B[0m 4ms/step - accuracy: 0.2294 - loss: 0.2316 - val_accuracy: 0.2923 - val_loss: 0.2229\n",
"Epoch 4/25\n",
"\u001B[1m22/22\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m0s\u001B[0m 4ms/step - accuracy: 0.2661 - loss: 0.2192 - val_accuracy: 0.3308 - val_loss: 0.2115\n",
"Epoch 5/25\n",
"\u001B[1m22/22\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m0s\u001B[0m 3ms/step - accuracy: 0.2661 - loss: 0.2092 - val_accuracy: 0.3385 - val_loss: 0.2021\n",
"Epoch 6/25\n",
"\u001B[1m22/22\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m0s\u001B[0m 4ms/step - accuracy: 0.3028 - loss: 0.2011 - val_accuracy: 0.3308 - val_loss: 0.1944\n",
"Epoch 7/25\n",
"\u001B[1m22/22\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m0s\u001B[0m 3ms/step - accuracy: 0.3028 - loss: 0.1943 - val_accuracy: 0.3231 - val_loss: 0.1877\n",
"Epoch 8/25\n",
"\u001B[1m22/22\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m0s\u001B[0m 4ms/step - accuracy: 0.2936 - loss: 0.1883 - val_accuracy: 0.3154 - val_loss: 0.1820\n",
"Epoch 9/25\n",
"\u001B[1m22/22\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m0s\u001B[0m 4ms/step - accuracy: 0.3394 - loss: 0.1829 - val_accuracy: 0.3615 - val_loss: 0.1768\n",
"Epoch 10/25\n",
"\u001B[1m22/22\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m0s\u001B[0m 4ms/step - accuracy: 0.3670 - loss: 0.1782 - val_accuracy: 0.4154 - val_loss: 0.1720\n",
"Epoch 11/25\n",
"\u001B[1m22/22\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m0s\u001B[0m 4ms/step - accuracy: 0.4037 - loss: 0.1738 - val_accuracy: 0.4538 - val_loss: 0.1678\n",
"Epoch 12/25\n",
"\u001B[1m22/22\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m0s\u001B[0m 4ms/step - accuracy: 0.4312 - loss: 0.1698 - val_accuracy: 0.4923 - val_loss: 0.1638\n",
"Epoch 13/25\n",
"\u001B[1m22/22\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m0s\u001B[0m 4ms/step - accuracy: 0.4679 - loss: 0.1661 - val_accuracy: 0.5154 - val_loss: 0.1601\n",
"Epoch 14/25\n",
"\u001B[1m22/22\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m0s\u001B[0m 4ms/step - accuracy: 0.4679 - loss: 0.1627 - val_accuracy: 0.5538 - val_loss: 0.1567\n",
"Epoch 15/25\n",
"\u001B[1m22/22\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m0s\u001B[0m 3ms/step - accuracy: 0.5046 - loss: 0.1594 - val_accuracy: 0.5615 - val_loss: 0.1533\n",
"Epoch 16/25\n",
"\u001B[1m22/22\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m0s\u001B[0m 4ms/step - accuracy: 0.5046 - loss: 0.1562 - val_accuracy: 0.5538 - val_loss: 0.1501\n",
"Epoch 17/25\n",
"\u001B[1m22/22\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m0s\u001B[0m 4ms/step - accuracy: 0.5229 - loss: 0.1531 - val_accuracy: 0.5846 - val_loss: 0.1470\n",
"Epoch 18/25\n",
"\u001B[1m22/22\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m0s\u001B[0m 3ms/step - accuracy: 0.5505 - loss: 0.1499 - val_accuracy: 0.6231 - val_loss: 0.1439\n",
"Epoch 19/25\n",
"\u001B[1m22/22\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m0s\u001B[0m 3ms/step - accuracy: 0.5780 - loss: 0.1469 - val_accuracy: 0.6615 - val_loss: 0.1410\n",
"Epoch 20/25\n",
"\u001B[1m22/22\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m0s\u001B[0m 4ms/step - accuracy: 0.6147 - loss: 0.1438 - val_accuracy: 0.6615 - val_loss: 0.1381\n",
"Epoch 21/25\n",
"\u001B[1m22/22\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m0s\u001B[0m 3ms/step - accuracy: 0.6422 - loss: 0.1410 - val_accuracy: 0.6769 - val_loss: 0.1353\n",
"Epoch 22/25\n",
"\u001B[1m22/22\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m0s\u001B[0m 3ms/step - accuracy: 0.6697 - loss: 0.1382 - val_accuracy: 0.7000 - val_loss: 0.1326\n",
"Epoch 23/25\n",
"\u001B[1m22/22\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m0s\u001B[0m 3ms/step - accuracy: 0.6972 - loss: 0.1354 - val_accuracy: 0.7077 - val_loss: 0.1299\n",
"Epoch 24/25\n",
"\u001B[1m22/22\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m0s\u001B[0m 3ms/step - accuracy: 0.7248 - loss: 0.1327 - val_accuracy: 0.7308 - val_loss: 0.1273\n",
"Epoch 25/25\n",
"\u001B[1m22/22\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m0s\u001B[0m 3ms/step - accuracy: 0.7523 - loss: 0.1303 - val_accuracy: 0.7615 - val_loss: 0.1248\n",
"\n",
"Skuteczność modelu na zbiorze testowym: 76.15%\n"
]
}
],
"execution_count": 167
}
],
"metadata": {
"kernelspec": {
"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.13.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}