/
sat1988
/
MachineVision
Обзор
Документация
Войти
/
sat1988
/
MachineVision
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
task05/tesorFlow.py
31 строка
971 B
Oleg Chorakaev
Добавлен 5 пример
26 июл 2025, 16:03
26 июл 2025, 16:03
9c85133
Код
Авторство
О чём код?
import numpy as np import tensorflow as tf from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Dense # Define the XOR input and output data X = np.array([[0, 0], [0, 1], [1, 0], [1, 1]]) y = np.array([[0], [1], [1], [0]]) # Build the neural network model model = Sequential() model.add(Dense(2, input_dim=2, activation='relu')) # Hidden layer with 2 neurons model.add(Dense(1, activation='sigmoid')) # Output layer with 1 neuron # Compile the model model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy']) # Train the model model.fit(X, y, epochs=10000, verbose=0) # Evaluate the model _, accuracy = model.evaluate(X, y) print(f"Accuracy: {accuracy * 100:.2f}%") # Make predictions predictions = model.predict(X) predictions = np.round(predictions).astype(int) print("Predictions:") for i in range(len(X)): print(f"Input: {X[i]} => Predicted Output: {predictions[i]}, Actual Output: {y[i]}")