我正在使用KNN创建机器学习算法,但是即使我从教程中复制了代码,我的space.distance.cosine函数也向我抛出错误。
我尝试查找问题,但没有得到任何结果
def computeDistance(a, b):
genresA = a[1]
genresB = b[1]
genreDistance = spatial.distance.cosine(genresA, genresB)
popularityA = a[2]
popularityB = b[2]
popularityDistance = abs(popularityA - popularityB)
return genreDistance + popularityDistance
"""
My error:
<ipython-input-12-997e6c661ba0> in computeDistance(a, b)
4 genresA = a[1]
5 genresB = b[1]
----> 6 genreDistance = spatial.distance.cosine(genresA, genresB)
7 popularityA = a[2]
8 popularityB = b[2]
"""
我希望输出为浮点值。 但是我收到一条错误消息,说“ TypeError”和已注释的消息。