import numpy as np import tensorflow as tf from sklearn.datasets import load_iris from sklearn.model_selection import train_test_split from tensorflow.keras import layers from tensorflow.keras.utils import to_categorical # Getting data data_set = load_iris() x = data_set['data'] y = to_categorical(data_set['target']) train_x, test_x, train_y, test_y = train_test_split(x, y, test_size=0.2) # Building the model model = tf.keras.Sequential() model.add(layers.Dense(20, activation='relu', input_dim=4)) model.add(layers.Dense(3, activation='sigmoid')) model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy']) # Training the model model.fit(train_x, train_y, validation_data=(test_x, test_y), epochs=1000) model.save('iris_model.h5')