KindXiaoming / pykan

Kolmogorov Arnold Networks
MIT License
13.9k stars 1.25k forks source link

Trouble using symbolic_formula for binary classification #301

Closed Yagnik12599 closed 1 week ago

Yagnik12599 commented 2 weeks ago

I have created a binary classification model using KAN, and got accuracy of 1., and now I decided to try the interpretability feature, and used the symbolic_formula, adn tried to get the accuracy to only find that the accuracy dipping to 0.67 (which basically means that the formula is only predicting 1 class i.e 0) according to my dataset. Any idea what might be causing this issue? I also did F1 score and AUC curve of the trained model, and everything suggests that the classification is working perfectly, then why does symbolic formula not work?

This is the line for auto_symbolic:

lib = ['x','x^2','x^3','x^4','exp','log','sqrt','tanh','sin','abs']
kan_model.auto_symbolic(lib=lib)

![Screenshot 2024-07-05 at 17 21 59](https://github.com/KindXiao

This is my model.plot() figure: Screenshot 2024-07-05 at 17 24 56 ming/pykan/assets/114891401/e17f7d36-bef7-44d1-b060-0ac1f026b87b)

Yagnik12599 commented 2 weeks ago

Screenshot 2024-07-05 at 17 26 30

Also this is how I am checking the accuracy.

Any help is appreciated. Thanks!

Euron-ZC commented 2 weeks ago

I have met similar problems, the formula 's performance is worse than model itself.

KindXiaoming commented 1 week ago

It's likely. The 1D functions learned by KANs are not necessarily symbolic, so symbolic snapping may harm performance. It might help to try

model = KAN(..., base_fun='identity', ...)
model.fit(.., lamb=0.01, lamb_coef=1.0)

so that in training, activation functions are encouraged to be linear, so less likely to learn some weird functions.