





#USING IRIS DATASET 


import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.utils import to_categorical
from sklearn.model_selection import train_test_split
from sklearn.datasets import load_iris


data = load_iris()
data


X = data.data
y = data.target

y = to_categorical(y, num_classes=3)
y

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
model = Sequential()
model.add(Dense(64, input_dim=X_train.shape[1], activation='relu')) # First hidden layer
model.add(Dense(32, activation='relu')) # Second hidden layer


model.add(Dense(3, activation='softmax'))
model.compile(optimizer=Adam(), loss='categorical_crossentropy', metrics=['accuracy'])
import time
start_time = time.time()
model.fit(X_train, y_train, epochs=50, batch_size=120, validation_data=(X_test, y_test))
end_time = time.time()
print("Time taken to train the model: {:.2f} seconds".format(end_time - start_time))


import numpy as np
predictions = model.predict(X_test) # Added this line to get predictions
predicted_classes = np.argmax(predictions, axis=1)
print("Predicted classes:", predicted_classes)

loss, accuracy = model.evaluate(X_test, y_test)
print(f"Test Loss: {loss}")
print(f"Test Accuracy: {accuracy}")