资源简介
使用python实现中文文本聚类,利用kmeans算法,包含jiba分词方法等
代码片段和文件信息
‘‘‘
Created on Mar 24 2011
Ch 11 code
@author: Peter
‘‘‘
from numpy import *
def loadDataSet():
return [
[12]
[2345]
[1346]
[2134]
[2136]
]
def createC1(dataSet):
C1 = []
for transaction in dataSet:
for item in transaction:
if not [item] in C1:
C1.append([item])
C1.sort()
return map(frozenset C1)#use frozen set so we
#can use it as a key in a dict
def scanD(D Ck minSupport):
ssCnt = {}
for tid in D:
for can in Ck:
if can.issubset(tid):
if not ssCnt.has_key(can): ssCnt[can]=1
else: ssCnt[can] += 1
numItems = float(len(D))
retList = []
supportData = {}
for key in ssCnt:
support = ssCnt[key]/numItems
if support >= minSupport:
retList.insert(0key)
supportData[key] = support
return retList supportData
def aprioriGen(Lk k): #creates Ck
retList = []
lenLk = len(Lk)
for i in range(lenLk):
for j in range(i+1 lenLk):
L1 = list(Lk[i])[:k-2];
L2 = list(Lk[j])[:k-2]
L1.sort();
L2.sort()
print L1L2
if L1==L2: #if first k-2 elements are equal
retList.append(Lk[i] | Lk[j]) #set union
return retList
def apriori(dataSet minSupport = 0.5):
C1 = createC1(dataSet)
D = map(set dataSet)
L1 supportData = scanD(D C1 minSupport)
L = [L1]
k = 2
while (len(L[k-2]) > 0):
Ck = aprioriGen(L[k-2] k)
Lk supK = scanD(D Ck minSupport)#scan DB to get Lk
supportData.update(supK)
L.append(Lk)
k += 1
return L supportData
def generateRules(L supportData minConf=0.7): #supportData is a dict coming from scanD
bigRuleList = []
for i in range(1 len(L)):#only get the sets with two or more items
for freqSet in L[i]:
H1 = [frozenset([item]) for item in freqSet]
if (i > 1):
rulesFromConseq(freqSet H1 supportData bigRuleList minConf)
else:
calcConf(freqSet H1 supportData bigRuleList minConf)
return bigRuleList
def calcConf(freqSet H supportData brl minConf=0.7):
prunedH = [] #create new list to return
for conseq in H:
conf = supportData[freqSet]/supportData[freqSet-conseq] #calc confidence
if conf >= minConf:
print freqSet-conseq‘-->‘conseq‘conf:‘conf
brl.append((freqSet-conseq conseq conf))
prunedH.append(conseq)
return prunedH
def rulesFromConseq(freqSet H supportData brl minConf=0.7):
m = len(H[0])
if (len(freqSet) > (m + 1)): #try further merging
Hmp1 = aprioriGen(H m+1)#create Hm+1 new candidates
Hmp1
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2015-10-11 04:20 chinese_text_cluster-master\
目录 0 2015-10-11 04:20 chinese_text_cluster-master\Association_Analysis\
目录 0 2015-10-11 04:20 chinese_text_cluster-master\Association_Analysis\Apriori\
文件 6012 2015-10-11 04:20 chinese_text_cluster-master\Association_Analysis\Apriori\apriori.py
文件 5189 2015-10-11 04:20 chinese_text_cluster-master\Association_Analysis\Apriori\apriori.pyc
文件 38906 2015-10-11 04:20 chinese_text_cluster-master\Association_Analysis\Apriori\bills20DataSet.txt
文件 137426 2015-10-11 04:20 chinese_text_cluster-master\Association_Analysis\Apriori\lawAssnRules.txt
文件 1806 2015-10-11 04:20 chinese_text_cluster-master\Association_Analysis\Apriori\meaning20.txt
文件 570408 2015-10-11 04:20 chinese_text_cluster-master\Association_Analysis\Apriori\mushroom.dat
文件 5585 2015-10-11 04:20 chinese_text_cluster-master\Association_Analysis\Apriori\recent100bills.txt
文件 1050 2015-10-11 04:20 chinese_text_cluster-master\Association_Analysis\Apriori\recent20bills.txt
目录 0 2015-10-11 04:20 chinese_text_cluster-master\Association_Analysis\FP-growth\
文件 6615 2015-10-11 04:20 chinese_text_cluster-master\Association_Analysis\FP-growth\fpGrowth.py
目录 0 2015-10-11 04:20 chinese_text_cluster-master\Classification\
目录 0 2015-10-11 04:20 chinese_text_cluster-master\Classification\AdaBoost\
目录 0 2015-10-11 04:20 chinese_text_cluster-master\Classification\AdaBoost\EXTRAS\
文件 522 2015-10-11 04:20 chinese_text_cluster-master\Classification\AdaBoost\EXTRAS\README.txt
文件 784 2015-10-11 04:20 chinese_text_cluster-master\Classification\AdaBoost\EXTRAS\simpleDataPlot.py
文件 5548 2015-10-11 04:20 chinese_text_cluster-master\Classification\AdaBoost\adaboost.py
文件 4719 2015-10-11 04:20 chinese_text_cluster-master\Classification\AdaBoost\adaboost.pyc
文件 13614 2015-10-11 04:20 chinese_text_cluster-master\Classification\AdaBoost\horseColicTest2.txt
文件 60778 2015-10-11 04:20 chinese_text_cluster-master\Classification\AdaBoost\horseColicTraining2.txt
文件 3462 2015-10-11 04:20 chinese_text_cluster-master\Classification\AdaBoost\old_adaboost.py
目录 0 2015-10-11 04:20 chinese_text_cluster-master\Classification\Bayes\
目录 0 2015-10-11 04:20 chinese_text_cluster-master\Classification\Bayes\EXTRAS\
文件 522 2015-10-11 04:20 chinese_text_cluster-master\Classification\Bayes\EXTRAS\README.txt
文件 961 2015-10-11 04:20 chinese_text_cluster-master\Classification\Bayes\EXTRAS\create2Normal.py
文件 456 2015-10-11 04:20 chinese_text_cluster-master\Classification\Bayes\EXTRAS\monoDemo.py
文件 7247 2015-10-11 04:20 chinese_text_cluster-master\Classification\Bayes\bayes.py
文件 6957 2015-10-11 04:20 chinese_text_cluster-master\Classification\Bayes\bayes.pyc
文件 15141 2015-10-11 04:20 chinese_text_cluster-master\Classification\Bayes\email.zip
............此处省略3084个文件信息
相关资源
- 机器学习对应的相关python代码SVM、C
- python 后台管理系统
- 声纹识别资料
- Introduction to time series.pdf + Deep Time Se
- OpenCV-Python中文教程
- 《廖雪峰Python2.7教程》高清完整PDF版
- Python标准库查询手册最新Python 3.3
- The Quick Python Book 3rd Edition.pdf
- Python学习思维导图
- OpenCV Python中文教程
- python for eclipse
- numpy-1.16.4.zip
- Python程序设计第3版- John M. Zelle 课件资
- Web Scraping with Python_Collecting Data from
- python TensorFlow 官方文档中文版
- Python3.6 中文文档.pdf
- 树莓派Python编程指南34705
- python项目源码
- Packt-Web.Scraping.with.Python.Richard Lawson
- Python编程实战:运用设计模式、并发
- 深入理解Python中文版.pdf
- QT5 Python GUI Programming Cookbook (2018)
- Hands-On Unsupervised Learning Using Python ep
- Jason Brownlee - Deep Learning with Python 高清
- Jason Brownlee - Machine learning Mastery with
- python27_d.dll
- python 情感分析 语料
- 上海交通大学Python课件ppt
-
树莓派人脸识别python代码及xm
l模型 - Python for Everybody
评论
共有 条评论