I am trying to deal with the python 2-package anfis
and as an experiment I used the load_iris()
-dataset from sklearn. If i want to use the plotMF
-function, the anfis-Code says, that i have the arguments self,x and InputVar (take a look here in the anfis.py-folder https://github.com/twmeggs/anfis). I try to plot it, but the error in my question occurs. I don't really know what to use as x and as InputVar...
所以这是我的代码:
import anfis
from anfis.membership import membershipfunction, mfDerivs
import numpy
from sklearn.datasets import load_iris
data = load_iris()
X = data['data']
Y = data['target']
#training_data = numpy.loadtxt("training.txt", usecols=[1,2,3])
#X = training_data [:,0:2]
#Y = training_data [:,2]
# Defining the Membership Functions
mf = [[['gaussmf',{'mean':0.,'sigma':1.}],['gaussmf',{'mean':-1.,'sigma':2.}],['gaussmf',{'mean':-4.,'sigma':10.}],['gaussmf',{'mean':-7.,'sigma':7.}]],
[['gaussmf',{'mean':1.,'sigma':2.}],['gaussmf',{'mean':2.,'sigma':3.}],['gaussmf',{'mean':-2.,'sigma':10.}],['gaussmf',{'mean':-10.5,'sigma':5.}]],
[['gaussmf',{'mean':0.,'sigma':1.}],['gaussmf',{'mean':-1.,'sigma':2.}],['gaussmf',{'mean':-4.,'sigma':10.}],['gaussmf',{'mean':-7.,'sigma':7.}]],
[['gaussmf',{'mean':1.,'sigma':2.}],['gaussmf',{'mean':2.,'sigma':3.}],['gaussmf',{'mean':-2.,'sigma':10.}],['gaussmf',{'mean':-10.5,'sigma':5.}]]]
# Updating the model with Membership Functions
mfc = membershipfunction.MemFuncs(mf)
# Creating the ANFIS Model Object
from anfis import anfis
anf = anfis.ANFIS(X, Y, mfc)
# Fitting the ANFIS Model
anf.trainHybridJangOffLine(epochs=10)
anf.plotMF(mf, X)
错误是:
TypeErrorTraceback (most recent call last)
<ipython-input-16-4dad5ff01e5b> in <module>()
----> 1 anf.plotMF(mf, X)
C:\Users\elihe\anaconda3\envs\py27\lib\site-packages\anfis\anfis.pyc in plotMF(self, x, inputVar)
146 from skfuzzy import gaussmf, gbellmf, sigmf
147
--> 148 for mf in range(len(self.memFuncs[inputVar])):
149 if self.memFuncs[inputVar][mf][0] == 'gaussmf':
150 y = gaussmf(x,**self.memClass.MFList[inputVar][mf][1])
TypeError: only integer scalar arrays can be converted to a scalar index