kenoma / KerasFuzzy

This is an attempt to implement neuro-fuzzy system on keras
27 stars 5 forks source link

TypeError: <lambda>() got an unexpected keyword argument 'dtype' #2

Closed raiuli closed 5 years ago

raiuli commented 5 years ago

HI

thanks for the nice work. however, when I am trying to run it I am getting the following error. i am using python2.7 , keras 2.2.5, teras 1.14. do i have to use some other version Traceback (most recent call last): File "/Users/raiuli/PycharmProjects/KerasFuzzy/KerasFuzzy/case2_neuro_fuzzy.py", line 20, in initializer_sigmas=lambda x:[[1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1], File "/usr/local/lib/python2.7/site-packages/keras/engine/sequential.py", line 166, in add layer(x) File "/usr/local/lib/python2.7/site-packages/keras/engine/base_layer.py", line 425, in call self.build(unpack_singleton(input_shapes)) File "/Users/raiuli/PycharmProjects/KerasFuzzy/KerasFuzzy/FuzzyLayer.py", line 24, in build trainable=True) File "/usr/local/lib/python2.7/site-packages/keras/legacy/interfaces.py", line 91, in wrapper return func(*args, **kwargs) File "/usr/local/lib/python2.7/site-packages/keras/engine/base_layer.py", line 243, in add_weight weight = K.variable(initializer(shape, dtype=dtype), TypeError: () got an unexpected keyword argument 'dtype'

kenoma commented 5 years ago

Hello, I need to check what have been changed in Keras 2.2.5, but I'm not sure that this is the case (my current keras is 2.2.4). I'll do this soon. At meantime are you sure that python2.7 is ok?

raiuli commented 5 years ago

HI, i have changed Keras to 2.1.5. then it works. Python 2.7 is ok. should i change it to python3.0. Do you follow any theoretical aspect of fuzzy? I mean any specific paper/book that you follow to implement it. I am trying to implement the following paper "A novel fuzzy deep-learning approach to traffic flow prediction with uncertain spatial–temporal data features" by Weihong Chen, Jiyao An , Renfa Li a, Li Fu, Guoqi Xie, Md Zakirul Alam Bhuiyan,Keqin Li". Do you think it will be possiable

kenoma commented 5 years ago

I have followed common concepts of ANFIS, which are pretty simple and well known (for example see this paper). In my realization you can find two layers - FuzzyLayer and DefuzzyLayer. With FuzzyLayer you can transform your input into rules firing levels and pass them into network whatever structure you like - dnn, cnn, lstm, etc. With DefuzzyLayer you can transform input, tracted as firing levels of some rules, into rules outcome.

Main drawbacks of this implementation (may be ANFIS in common too) is a hight probability to stuck during training phase. You need to initializate fuzzy layers parameters in near optimal state to fine tune them with training. This is inpractical in most real word cases.

Back to "A novel fuzzy deep-learning approach to traffic flow prediction with uncertain spatial–temporal data features" by Weihong Chen, Jiyao An , Renfa Li a, Li Fu, Guoqi Xie, Md Zakirul Alam Bhuiyan,Keqin Li" I suppose you can implement it with use FuzzyLayer and embedded Keras layers.

raiuli commented 5 years ago

Thanks for the input. I have used keras.layers.concatenate to merge the output from fuzzy layer and CNN. also using the Keras functional API to do it. thanks for inputs and the nice work

kenoma commented 5 years ago

You're welcome. If you obtain interesting results I'll be glad to know it.

navya-git-sw commented 2 years ago

Hi, I got similar error when I ran the iris dataset code. I am just running your code. TypeError: <lambda>() got an unexpected keyword argument 'dtype'

keras version is 2.8.0. Is the code work only for keras version 2.1.5

navya-git-sw commented 2 years ago

can we implement ANFIS algorithm to predict the credit defaulters. does it works for classification problems well than other machine learning models like random forest, xgboost etc.

I have seen ANFIS implementaton for defaulters in below research paper https://jfin-swufe.springeropen.com/track/pdf/10.1186/s40854-019-0121-9.pdf

kenoma commented 2 years ago

Hi, I got similar error when I ran the iris dataset code. I am just running your code. TypeError: <lambda>() got an unexpected keyword argument 'dtype'

keras version is 2.8.0. Is the code work only for keras version 2.1.5

I have not adapted code to newer versions of keras yet. If you interested in it I'll do this.

can we implement ANFIS algorithm to predict the credit defaulters. does it works for classification problems well than other machine learning models like random forest, xgboost etc.

I have seen ANFIS implementaton for defaulters in below research paper https://jfin-swufe.springeropen.com/track/pdf/10.1186/s40854-019-0121-9.pdf

My personal opinion it that fuzzy logic is a good tool to encode real world input into more sophisticated ml model, but FIS itself has no advantages on rf, xboost and etc in general case.

navya-git-sw commented 2 years ago

@kenoma , Thank you for responding .if you don't mind can you update the code for newer version because i can downgrade the keras version but couldn't downgrade the backend tensor flow version.

can we print rules of fuzzy layer (like apriori algorithm print the rules)instead printing the graphs of rules

navya-git-sw commented 2 years ago

It means random forest, xgboost are better than ANFIS algorithm?

kenoma commented 2 years ago

It means random forest, xgboost are better than ANFIS algorithm?

Depends on task. For example, if you deal with continuous variables you may found ANFIS more reasonable and suitable than decisions trees. In general case it is easy to build model based on neural networks or boosting. Only benefit of using ANFIS in cases that can be easily solved by other models is interpretability.

navya-git-sw commented 2 years ago

Okay. Thank you for your inputs.