0% found this document useful (0 votes)
74 views1 page

Solving Xor Problem Using DNN

The document outlines a Python script that solves the XOR problem using a Deep Neural Network (DNN) with TensorFlow. It defines a model with one hidden layer and trains it on XOR data, achieving binary classification. The script also evaluates the model's performance and makes predictions, rounding them to binary outputs.

Uploaded by

mentorsahila
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views1 page

Solving Xor Problem Using DNN

The document outlines a Python script that solves the XOR problem using a Deep Neural Network (DNN) with TensorFlow. It defines a model with one hidden layer and trains it on XOR data, achieving binary classification. The script also evaluates the model's performance and makes predictions, rounding them to binary outputs.

Uploaded by

mentorsahila
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

SOLVING XOR PROBLEM USING DNN

import numpy as np
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
# XOR problem data
X = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])
y = np.array([[0], [1], [1], [0]])
# Define the model
model = Sequential()
model.add(Dense(4, input_dim=2, activation='relu')) # Hidden layer with 4
neurons and ReLU activation
model.add(Dense(1, activation='sigmoid')) # Output layer with 1 neuron and
sigmoid activation
# Compile the model
model.compile(loss='binary_crossentropy', optimizer='adam',
metrics=['accuracy'])
# Train the model
model.fit(X, y, epochs=500, verbose=0)
# Evaluate the model (optional)
loss, accuracy = model.evaluate(X, y)
print(f"Loss: {loss:.4f}, Accuracy: {accuracy:.4f}")
# Make predictions
predictions = model.predict(X)
print("\nPredictions:")
print(np.round(predictions)) # Round predictions to get binary output

You might also like