1
\$\begingroup\$

Compared to my another post Logistic Regression for non linearly separable data which uses one-layer net, i.e. Logistic Regression to classify the iris data set, this post is to discuss the tensorflow method.

iris = load_iris()
x_train, x_test, y_train, y_test = train_test_split(
    iris.data, iris.target, test_size=0.33, random_state=2021)
y_train=np_utils.to_categorical(y_train, num_classes=3)
y_test=np_utils.to_categorical(y_test, num_classes=3)


model = tf.keras.Sequential([
    tf.keras.layers.Dense(500, input_dim=4, activation='relu'),
    tf.keras.layers.Dense(256, activation='relu'),
    tf.keras.layers.Dense(256, activation='relu'),
    tf.keras.layers.Dense(128, activation='relu'),
    tf.keras.layers.Dropout(0.2),
    tf.keras.layers.Dense(128, activation='relu'),
    tf.keras.layers.Dense(3, activation='softmax')
])

model.compile(loss='categorical_crossentropy',
              optimizer='adam',
              metrics=['accuracy'])


model.fit(x_train,y_train, validation_data=(x_test,y_test), batch_size=20,epochs=30,verbose=0)


prediction=model.predict(x_train)
length=len(prediction)
y_label=np.argmax(y_train,axis=1)
predict_label=np.argmax(prediction,axis=1)

accuracy=np.sum(y_label==predict_label)/length * 100 
print("Accuracy of the dataset",accuracy )


prediction=model.predict(x_test)
length=len(prediction)
y_label=np.argmax(y_test,axis=1)
predict_label=np.argmax(prediction,axis=1)

accuracy=np.sum(y_label==predict_label)/length * 100 
print("Accuracy of the dataset",accuracy )

The accuracy is

Accuracy of the dataset 99.0
Accuracy of the dataset 94.0

I've tried several times, this is the best performance.

I also tried more and less neurons and layers, the one above is the best.

\$\endgroup\$
1
  • \$\begingroup\$ As I understand from your post (and previous post) you are not looking for a code review, you are looking for a model review. I believe this is not the correct platform for you to look for answers. Consider looking online for Hyper-parameter Tuning Techniques. \$\endgroup\$
    – Yonlif
    Commented Aug 7, 2021 at 12:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.