Bad example for variational classifier iris classification demo

I use this iris data in variational classifier iris classification demo.

import pandas as pd
from sklearn import datasets

iris = datasets.load_iris()

df = pd.DataFrame(, columns=iris.feature_names)
df['target'] =
df['target_names'] = iris.target_names[]

x_train = df.loc[:, ['petal length (cm)', 'petal width (cm)']].to_numpy()

y_train =
y_train = [int(e / 2) for e in y_train]

X = x_train
Y = [(-1 if e==1 else 1) for e in y_train]
Y = np.tensor(Y, requires_grad=True)

But I get the bad result. I wonder how to improve model or why.

Hey @tudouuuuu!

Just want to make sure that you’re referring to this demo? I.e., you’re using the code in the Iris Classification section but just replacing the data there with the content in your post?

Yes, I am using code in the Iris classification

I also changed last plot code. I replaced xx, yy in this way:


xx, yy = np.meshgrid(np.linspace(0.0, 1.5, 20), np.linspace(0.0, 1.5, 20))


xx, yy = np.meshgrid(np.arange(X[:, 0].min() - 0.5, X[:, 0].max() + 0.5, 0.05), np.arange(X[:, 1].min() - 0.5, X[:, 1].max() + 0.5, 0.05))

Could you please attach the notebook that you’re working with? It’s hard to pinpoint exactly what’s going on without seeing your entire code.

Please look here

I find when I change the number of iteration to 51 or 52, the result is good.
Thanks for your reply! @isaacdevlugt

Glad your issue is solved! I suspected it was probably just an issue with hyperparameter choices… Awesome job!

1 Like