import numpy as np from keras.models import Sequential from keras.layers import Dense # Генерация данных X = np.random.rand(1000, 2) * 100 # Два входных числа y = np.sum(X, axis=1) # Сумма двух чисел # Создание модели model = Sequential([ Dense(10, activation='relu', input_dim=2), # Скрытый слой Dense(1) # Выходной слой ]) # Компиляция модели model.compile(optimizer='adam', loss='mse', metrics=['mae']) # Обучение модели model.fit(X, y, epochs=50, batch_size=32, verbose=1) # Тестирование модели test_data = np.array([[10, 20], [30, 40]]) # Тестовые данные predictions = model.predict(test_data) print("Входные данные:", test_data) print("Предсказания суммы:", predictions)
Standard input is empty
Epoch 1/50 1/32 [..............................] - ETA: 12s - loss: 17994.6836 - mae: 123.9936 32/32 [==============================] - 0s 992us/step - loss: 15043.3994 - mae: 113.7642 Epoch 2/50 1/32 [..............................] - ETA: 0s - loss: 12715.4141 - mae: 106.2181 32/32 [==============================] - 0s 745us/step - loss: 12456.8154 - mae: 103.3911 Epoch 3/50 1/32 [..............................] - ETA: 0s - loss: 12651.3545 - mae: 102.6296 32/32 [==============================] - 0s 768us/step - loss: 10291.4541 - mae: 93.6963 Epoch 4/50 1/32 [..............................] - ETA: 0s - loss: 7915.7515 - mae: 80.7487 32/32 [==============================] - 0s 775us/step - loss: 8356.4893 - mae: 84.0192 Epoch 5/50 1/32 [..............................] - ETA: 0s - loss: 7286.2598 - mae: 78.4910 32/32 [==============================] - 0s 748us/step - loss: 6445.7681 - mae: 73.2368 Epoch 6/50 1/32 [..............................] - ETA: 0s - loss: 4720.6709 - mae: 62.4819 32/32 [==============================] - 0s 886us/step - loss: 4527.2329 - mae: 60.6766 Epoch 7/50 1/32 [..............................] - ETA: 0s - loss: 3132.5527 - mae: 50.9019 32/32 [==============================] - 0s 749us/step - loss: 2977.2766 - mae: 48.3118 Epoch 8/50 1/32 [..............................] - ETA: 0s - loss: 2079.7888 - mae: 38.7474 32/32 [==============================] - 0s 742us/step - loss: 1864.7711 - mae: 36.9307 Epoch 9/50 1/32 [..............................] - ETA: 0s - loss: 1695.5894 - mae: 35.7451 32/32 [==============================] - 0s 765us/step - loss: 1132.0267 - mae: 27.6227 Epoch 10/50 1/32 [..............................] - ETA: 0s - loss: 1061.7100 - mae: 26.5246 32/32 [==============================] - 0s 828us/step - loss: 704.4185 - mae: 21.1626 Epoch 11/50 1/32 [..............................] - ETA: 0s - loss: 701.6003 - mae: 20.8608 32/32 [==============================] - 0s 741us/step - loss: 469.2602 - mae: 17.1379 Epoch 12/50 1/32 [..............................] - ETA: 0s - loss: 477.9725 - mae: 17.7739 32/32 [==============================] - 0s 792us/step - loss: 343.8763 - mae: 14.8384 Epoch 13/50 1/32 [..............................] - ETA: 0s - loss: 293.9790 - mae: 12.7346 32/32 [==============================] - 0s 722us/step - loss: 277.1958 - mae: 13.3708 Epoch 14/50 1/32 [..............................] - ETA: 0s - loss: 380.3908 - mae: 15.8154 32/32 [==============================] - 0s 791us/step - loss: 236.1098 - mae: 12.4043 Epoch 15/50 1/32 [..............................] - ETA: 0s - loss: 211.4024 - mae: 11.4865 32/32 [==============================] - 0s 771us/step - loss: 207.7698 - mae: 11.6930 Epoch 16/50 1/32 [..............................] - ETA: 0s - loss: 211.9588 - mae: 12.4728 32/32 [==============================] - 0s 753us/step - loss: 184.7477 - mae: 11.0577 Epoch 17/50 1/32 [..............................] - ETA: 0s - loss: 115.9901 - mae: 8.8368 32/32 [==============================] - 0s 748us/step - loss: 164.3435 - mae: 10.4618 Epoch 18/50 1/32 [..............................] - ETA: 0s - loss: 167.8185 - mae: 9.6286 32/32 [==============================] - 0s 753us/step - loss: 146.5209 - mae: 9.8822 Epoch 19/50 1/32 [..............................] - ETA: 0s - loss: 135.8714 - mae: 9.6453 32/32 [==============================] - 0s 766us/step - loss: 129.5890 - mae: 9.3017 Epoch 20/50 1/32 [..............................] - ETA: 0s - loss: 150.2193 - mae: 9.7654 32/32 [==============================] - 0s 744us/step - loss: 114.1228 - mae: 8.7286 Epoch 21/50 1/32 [..............................] - ETA: 0s - loss: 122.4537 - mae: 8.9737 32/32 [==============================] - 0s 759us/step - loss: 99.7815 - mae: 8.1558 Epoch 22/50 1/32 [..............................] - ETA: 0s - loss: 79.7344 - mae: 7.6491 32/32 [==============================] - 0s 729us/step - loss: 86.7438 - mae: 7.5868 Epoch 23/50 1/32 [..............................] - ETA: 0s - loss: 122.7631 - mae: 9.0030 32/32 [==============================] - 0s 795us/step - loss: 74.6562 - mae: 7.0145 Epoch 24/50 1/32 [..............................] - ETA: 0s - loss: 99.3830 - mae: 8.2459 32/32 [==============================] - 0s 758us/step - loss: 63.3396 - mae: 6.4152 Epoch 25/50 1/32 [..............................] - ETA: 0s - loss: 41.2305 - mae: 5.1827 32/32 [==============================] - 0s 761us/step - loss: 52.8558 - mae: 5.7890 Epoch 26/50 1/32 [..............................] - ETA: 0s - loss: 47.1080 - mae: 5.5305 32/32 [==============================] - 0s 736us/step - loss: 42.9401 - mae: 5.1128 Epoch 27/50 1/32 [..............................] - ETA: 0s - loss: 28.0925 - mae: 3.6100 32/32 [==============================] - 0s 777us/step - loss: 33.8389 - mae: 4.2919 Epoch 28/50 1/32 [..............................] - ETA: 0s - loss: 23.1631 - mae: 3.6190 32/32 [==============================] - 0s 753us/step - loss: 26.7396 - mae: 3.6471 Epoch 29/50 1/32 [..............................] - ETA: 0s - loss: 35.9374 - mae: 4.0932 32/32 [==============================] - 0s 755us/step - loss: 21.2876 - mae: 3.1713 Epoch 30/50 1/32 [..............................] - ETA: 0s - loss: 16.2571 - mae: 2.6051 32/32 [==============================] - 0s 746us/step - loss: 17.1589 - mae: 2.7530 Epoch 31/50 1/32 [..............................] - ETA: 0s - loss: 9.4529 - mae: 2.0940 32/32 [==============================] - 0s 726us/step - loss: 13.9412 - mae: 2.4092 Epoch 32/50 1/32 [..............................] - ETA: 0s - loss: 9.8611 - mae: 1.8823 32/32 [==============================] - 0s 774us/step - loss: 11.5823 - mae: 2.1792 Epoch 33/50 1/32 [..............................] - ETA: 0s - loss: 12.7286 - mae: 2.2153 32/32 [==============================] - 0s 753us/step - loss: 9.7004 - mae: 1.9811 Epoch 34/50 1/32 [..............................] - ETA: 0s - loss: 3.5636 - mae: 1.3453 32/32 [==============================] - 0s 758us/step - loss: 8.3049 - mae: 1.8778 Epoch 35/50 1/32 [..............................] - ETA: 0s - loss: 3.0787 - mae: 1.3620 32/32 [==============================] - 0s 715us/step - loss: 7.1936 - mae: 1.7975 Epoch 36/50 1/32 [..............................] - ETA: 0s - loss: 12.4507 - mae: 2.3491 32/32 [==============================] - 0s 737us/step - loss: 6.3439 - mae: 1.7322 Epoch 37/50 1/32 [..............................] - ETA: 0s - loss: 8.3348 - mae: 1.9189 32/32 [==============================] - 0s 750us/step - loss: 5.6764 - mae: 1.6680 Epoch 38/50 1/32 [..............................] - ETA: 0s - loss: 6.3518 - mae: 1.8144 32/32 [==============================] - 0s 750us/step - loss: 5.1587 - mae: 1.6251 Epoch 39/50 1/32 [..............................] - ETA: 0s - loss: 2.8955 - mae: 1.4158 32/32 [==============================] - 0s 742us/step - loss: 4.7277 - mae: 1.5947 Epoch 40/50 1/32 [..............................] - ETA: 0s - loss: 4.2506 - mae: 1.4462 32/32 [==============================] - 0s 721us/step - loss: 4.3650 - mae: 1.5655 Epoch 41/50 1/32 [..............................] - ETA: 0s - loss: 3.4752 - mae: 1.4980 32/32 [==============================] - 0s 763us/step - loss: 4.0796 - mae: 1.5281 Epoch 42/50 1/32 [..............................] - ETA: 0s - loss: 6.1971 - mae: 1.7984 32/32 [==============================] - 0s 782us/step - loss: 3.8431 - mae: 1.5078 Epoch 43/50 1/32 [..............................] - ETA: 0s - loss: 5.2304 - mae: 1.7992 32/32 [==============================] - 0s 757us/step - loss: 3.6554 - mae: 1.4820 Epoch 44/50 1/32 [..............................] - ETA: 0s - loss: 4.3824 - mae: 1.7548 32/32 [==============================] - 0s 726us/step - loss: 3.4867 - mae: 1.4668 Epoch 45/50 1/32 [..............................] - ETA: 0s - loss: 2.0130 - mae: 1.1654 32/32 [==============================] - 0s 730us/step - loss: 3.3444 - mae: 1.4501 Epoch 46/50 1/32 [..............................] - ETA: 0s - loss: 2.7753 - mae: 1.4331 32/32 [==============================] - 0s 743us/step - loss: 3.2247 - mae: 1.4346 Epoch 47/50 1/32 [..............................] - ETA: 0s - loss: 3.4632 - mae: 1.4531 32/32 [==============================] - 0s 756us/step - loss: 3.1118 - mae: 1.4156 Epoch 48/50 1/32 [..............................] - ETA: 0s - loss: 3.8059 - mae: 1.6296 32/32 [==============================] - 0s 753us/step - loss: 3.0175 - mae: 1.4064 Epoch 49/50 1/32 [..............................] - ETA: 0s - loss: 2.5673 - mae: 1.2272 32/32 [==============================] - 0s 720us/step - loss: 2.9358 - mae: 1.3876 Epoch 50/50 1/32 [..............................] - ETA: 0s - loss: 3.3745 - mae: 1.4896 32/32 [==============================] - 0s 758us/step - loss: 2.8625 - mae: 1.3846 Входные данные: [[10 20] [30 40]] Предсказания суммы: [[30.918484] [71.48034 ]]