如何修复MyCode中的KeyError:0

时间:2019-02-07 04:03:31

标签: python pandas sklearn-pandas

我在实现模糊knn https://github.com/sahilsehwag/FuzzyKNN时遇到麻烦,当我运行k最近邻居时,它可以工作但不模糊

def fit(self, X, y=None):
    self._check_params(X,y)
    self.X = X
    self.y = y

    self.xdim = len(self.X[0]) #in here
    self.n = len(y)

    classes = list(set(y))
    classes.sort()
    self.classes = classes

    self.df = pd.DataFrame(self.X)
    self.df['y'] = self.y

    self.memberships = self._compute_memberships()

    self.df['membership'] = self.memberships

    self.fitted_ = True
    return self

我跑步时出现错误

File "C: /Users/DELL/.spyder-py3/temp.py", line 172, in <module>
     custModel.fit (xTrain, yTrain)

File "C: /Users/DELL/.spyder-py3/temp.py", line 53, in fit
     self.xdim = len (self.X [0])

KeyError: 0

0 个答案:

没有答案