美文网首页
python-ML学习小记-L1-KNN

python-ML学习小记-L1-KNN

作者: 李大狗随随便便地 | 来源:发表于2016-12-21 14:12 被阅读0次

    from Distance import Distance

    cal=Distance()

    k=3

    s=[["t1",0],["t2",0]]

    pt=[[[1,2],s[0][0],"NaN"]

    ,[[3,2],s[0][0],"NaN"]

    ,[[4,3],s[0][0],"NaN"]

    ,[[6,6],s[1][0],"NaN"]

    ,[[6,7],s[1][0],"NaN"]]

    pre=[[4,1],"NaN"]

    pNum=len(pt)

    for i in range(pNum):

        pt[i][2]=cal.cEDistance(pt[i][0],pre[0])

    '''sort

    dis.sort()

    sort2'''

    for j in range(pNum-1):

        for i in range(pNum-1):

            if pt[i][2]>pt[i+1][2]:

                pt[i],pt[i+1]=pt[i+1],pt[i]

    print pt

    for i in range(k):

        for j in range(len(s)):

            if pt[i][1]==s[j][0]:

                s[j][1]+=1

    for i in range(len(s)-1):

        for i in range(len(s)-1):

            if s[i][1]<s[i+1][1]:

                s[i],s[i+1]=s[i+1],s[i]

    print s[0][0]

    相关文章

      网友评论

          本文标题:python-ML学习小记-L1-KNN

          本文链接:https://www.haomeiwen.com/subject/wpsqvttx.html