91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 2KB
    文件類型: .py
    金幣: 1
    下載: 0 次
    發布日期: 2021-01-09
  • 語言: Python
  • 標簽:

資源簡介

利用十大經典機器學習算法之一的KNN(K近鄰)算法,實現文本自動聚類。

資源截圖

代碼片段和文件信息

from?__future__?import?print_function

import?numpy?as?np
import?time
import?re
import?os
import?math
all=‘train.txt‘
latentpath=
normFlag=False
k=30
def?file2matrix(filelisttfidfpath?norm=False):
????fr?=?open(filelist)?????????
????files?=?[line.strip()?for?line?in?fr.readlines()]
????number_of_samples?=?len(files)?
????fr.close()
????list_of_line=files[0].split()
????FileTFIDF=os.path.join(tfidfpathfiles[0].split()[0])
????fd=open(FileTFIDF‘r‘)
????fea_dim=len(fd.readlines())
????fd.close()
????SampleMat?=?np.zeros((number_of_samplesfea_dim)dtype=float)
????Label=np.zeros((number_of_samples)dtype=np.int)
????fileindex?=?0
????for?file?in?files:
????????list_of_line=file.split()
????????FileTFIDF=os.path.join(tfidfpathlist_of_line[0])
????????str1=re.sub

評論

共有 條評論

相關資源