本文整理汇总了Python中minisom.MiniSom.weights方法的典型用法代码示例。如果您正苦于以下问题:Python MiniSom.weights方法的具体用法?Python MiniSom.weights怎么用?Python MiniSom.weights使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类minisom.MiniSom
的用法示例。
在下文中一共展示了MiniSom.weights方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_recommendation
# 需要导入模块: from minisom import MiniSom [as 别名]
# 或者: from minisom.MiniSom import weights [as 别名]
def test_recommendation():
uji_profil = db.uji_profil
current_seq = []
for t in uji_profil.find({}):
current_seq.append("Topik " + str(t['topic']))
'''
APPLY SOM
'''
allTopic = articles.distinct("topic")
lentopic = len(allTopic)
uniqueTopic = []
for t in allTopic:
uniqueTopic.append("Topik " + str(t).strip())
lebarSOM = lentopic*lentopic + lentopic*2 + 1
somInput = []
somInput.append(getPresedenceMatrix(convertSession(current_seq,uniqueTopic),uniqueTopic,1))
som = MiniSom(16,16,lentopic,sigma=1.0,learning_rate=0.5)
som.weights = numpy.load('weight_som.npy')
cluster_winner = ""
for cnt,xx in enumerate(somInput):
w = som.winner(xx) # getting the winner
cluster_winner = (str(w[0])+"-"+str(w[1]))
'''
SEARCH FOR THE PATTERN IN PARTICULAR CLUSTER
'''
print cluster_winner
print current_seq
prefix_result = db.prefix_result
prefix_cluster = prefix_result.find({"cluster":cluster_winner,"data_uji":no_uji}).sort("min_sup",pymongo.DESCENDING)
topik_rekomendasi = getTopikRekomendasi(current_seq,prefix_cluster)
if topik_rekomendasi == "":
prefix_cluster = prefix_result.find({"data_uji":no_uji}).sort("min_sup",pymongo.DESCENDING)
topik_rekomendasi = getTopikRekomendasi(current_seq,prefix_cluster)
html = "--tidak ada topik rekomendasi--"
if(topik_rekomendasi!=""):
the_topik = topik_rekomendasi.replace("Topik","").strip()
html = getTestArticle(the_topik,"Rekomendasi 1","accordion_recommendation",'col_rek1',"")
html += getTestArticle(the_topik,"Rekomendasi 2","accordion_recommendation",'col_rek2',"")
html += getTestArticle(the_topik,"Rekomendasi 3","accordion_recommendation",'col_rek3',"")
return html
示例2: test_som
# 需要导入模块: from minisom import MiniSom [as 别名]
# 或者: from minisom.MiniSom import weights [as 别名]
def test_som():
print "Clustering.."
session_log_db = db.session_log
allTopic = articles.distinct("topic")
lentopic = len(allTopic)
uniqueTopic = []
for t in allTopic:
uniqueTopic.append("Topik " + str(t).strip())
lebarSOM = lentopic*lentopic + lentopic*2 + 1
panjangSOM = session_log_db.find({"data_uji":no_uji}).count()
#somInput = zeros((panjangSOM,lebarSOM),dtype=int16)
somInput = []
oriSess = []
for s in session_log_db.find({"data_uji":no_uji}):
somInput.append(getPresedenceMatrix(convertSession(s["session"],uniqueTopic),uniqueTopic,1))
oriSess.append(s["session"])
som = MiniSom(16,16,lentopic,sigma=1.0,learning_rate=0.5)
som.weights = numpy.load('weight_som.npy')
#print som.weights
outfile = open('cluster-result.csv','w')
seq_number = 0
cluster_mongo = db.cluster_result
cluster_mongo.remove({"data_uji":no_uji})
for cnt,xx in enumerate(somInput):
w = som.winner(xx) # getting the winner
#print cnt
#print xx
#print w
#for z in xx:
# outfile.write("%s " % str(z))
outfile.write("%s " % str(("|".join(oriSess[seq_number]))))
outfile.write("%s-%s \n" % (str(w[0]),str(w[1])))
cluster_mongo.insert({"topik":"|".join(oriSess[seq_number]),"cluster":(str(w[0])+"-"+str(w[1])),"data_uji":no_uji})
seq_number = seq_number + 1
#outfile.write("%s %s\n" % str(xx),str(w))
# palce a marker on the winning position for the sample xx
#plot(w[0]+.5,w[1]+.5,markers[t[cnt]],markerfacecolor='None',
# markeredgecolor=colors[t[cnt]],markersize=12,markeredgewidth=2)
outfile.close()
#TopikCluster()
html = '<div role="alert" class="alert alert-success alert-dismissible fade in">'
html = html + ' <button aria-label="Close" data-dismiss="alert" class="close" type="button"><span aria-hidden="true">Close</span></button>'
html = html + 'Berhasil Melakukan Clustering</div>'
return html
示例3: test_som
# 需要导入模块: from minisom import MiniSom [as 别名]
# 或者: from minisom.MiniSom import weights [as 别名]
def test_som(alpha_som,omega_som):
print "Clustering pada Data Uji " + str(no_uji)
session_log_db = db.session_log
allTopic = articles.distinct("topic")
lentopic = len(allTopic)
uniqueTopic = []
for t in allTopic:
uniqueTopic.append("Topik " + str(t).strip())
lebarSOM = lentopic*lentopic + lentopic*2 + 1
panjangSOM = session_log_db.find({"data_uji":no_uji}).count()
#somInput = zeros((panjangSOM,lebarSOM),dtype=int16)
somInput = []
oriSess = []
for s in session_log_db.find({"data_uji":no_uji}):
somInput.append(getPresedenceMatrix(convertSession(s["session"],uniqueTopic),uniqueTopic,1))
oriSess.append(s["session"])
som = MiniSom(16,16,lentopic,sigma=omega_som,learning_rate=alpha_som)
som.weights = numpy.load('weight_som.npy')
#print som.weights
outfile = open('cluster-result.csv','w')
seq_number = 0
cluster_mongo = db.cluster_result
cluster_mongo.remove({"data_uji":no_uji})
for cnt,xx in enumerate(somInput):
w = som.winner(xx) # getting the winner
outfile.write("%s " % str(("|".join(oriSess[seq_number]))))
outfile.write("%s-%s \n" % (str(w[0]),str(w[1])))
cluster_mongo.insert({"topik":"|".join(oriSess[seq_number]),"cluster":(str(w[0])+"-"+str(w[1])),"data_uji":no_uji})
seq_number = seq_number + 1
outfile.close()
#TopikCluster()
return "Berhasil Melakukan Clustering"