TypeError: ‘tuple‘ object is not callable
程序员文章站
2022-05-29 08:04:18
...
复现机器学习KNN出现的错误。
def createDataset():
group = array([[1.0, 1.1],[1.0, 1.0], [0, 0], [0, 0.1]])
labels = ['A','A','B','B']
return group, labels
def classify0(inX, dataSet, labels, k):
dataSetSize = dataSet.shape(0)
diffMat = tile(inX, (dataSetSize, 1))- dataSet
sqdiffMat = diffMat**2
sqDistances = sqdiffMat.sum(axis=1)
distances = sqDistances**0.5
sortedDistIndicies = distances.argsort()
classCount={}
for i in range(k):
voteIlabel = labels[sortedDistIndicies[i]]
classCount[voteIlabel] = classCount.get(voteIlabel, 0) + 1
sortedClassCount = sorted(classCount.iteritems(),key = operator.itemgetter(1),reverse=True
)
return sortedClassCount[0][0]在这里插入代码片
第一个错误
TypeError: ‘tuple’ object is not callable
将下列代码
dataSetSize = dataSet.shape(0)
改成`
dataSetSize = dataSet.shape[0]
对于数据特征的引用一般都用[]
data.feature[index]
第二个错误:
AttributeError: ‘dict’ object has no attribute ‘iteritems’
sortedClassCount = sorted(classCount.items(),key = operator.itemgetter(1),reverse=True
中iteritems改成items
推荐阅读
-
python编程排除163邮箱发送邮件报错(AttributeError: ‘tuple‘ object has no attribute ‘encode‘)
-
python编程排除163邮箱发送邮件报错(AttributeError: ‘tuple‘ object has no attribute ‘encode‘)
-
Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object
-
Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object’#
-
TypeError: POST data should be bytes, an iterable of bytes, or a file object.制作有道翻译小翻译软件的问题解决方法
-
解决报错:TypeError: argument should be integer or bytes-like object, not ‘str‘
-
编译安卓源码提示:TypeError: argument should be integer or bytes-like object, not ‘str‘
-
TypeError: The value of a feed cannot be a tf.Tensor object.几种情况
-
TypeError: the JSON object must be str, bytes or bytearray, not NoneType
-
TypeError: POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type s