本文整理汇总了Python中minisom.MiniSom.distance_map方法的典型用法代码示例。如果您正苦于以下问题:Python MiniSom.distance_map方法的具体用法?Python MiniSom.distance_map怎么用?Python MiniSom.distance_map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类minisom.MiniSom
的用法示例。
在下文中一共展示了MiniSom.distance_map方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SOM
# 需要导入模块: from minisom import MiniSom [as 别名]
# 或者: from minisom.MiniSom import distance_map [as 别名]
def SOM(data,leninput,lentarget,alpha_som,omega_som):
som = MiniSom(16,16,leninput,sigma=omega_som,learning_rate=alpha_som)
som.random_weights_init(data)
print("Training...")
som.train_batch(data,20000) # training with 10000 iterations
print("\n...ready!")
numpy.save('weight_som',som.weights)
bone()
pcolor(som.distance_map().T) # distance map as background
colorbar()
t = zeros(lentarget,dtype=int)
# use different colors and markers for each label
markers = ['o','s','D']
colors = ['r','g','b']
outfile = open('cluster-result.csv','w')
for cnt,xx in enumerate(data):
w = som.winner(xx) # getting the winner
for z in xx:
outfile.write("%s " % str(z))
outfile.write("%s-%s \n" % (str(w[0]),str(w[1])))
outfile.close()
示例2: SOM
# 需要导入模块: from minisom import MiniSom [as 别名]
# 或者: from minisom.MiniSom import distance_map [as 别名]
def SOM(data,leninput,lentarget):
som = MiniSom(5,5,leninput,sigma=1.0,learning_rate=0.5)
som.random_weights_init(data)
print("Training...")
som.train_batch(data,10000) # training with 10000 iterations
print("\n...ready!")
numpy.save('weight_som.txt',som.weights)
bone()
pcolor(som.distance_map().T) # distance map as background
colorbar()
t = zeros(lentarget,dtype=int)
# use different colors and markers for each label
markers = ['o','s','D']
colors = ['r','g','b']
outfile = open('cluster-result.csv','w')
for cnt,xx in enumerate(data):
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-%s \n" % (str(w[0]),str(w[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()
示例3: testSOMs
# 需要导入模块: from minisom import MiniSom [as 别名]
# 或者: from minisom.MiniSom import distance_map [as 别名]
def testSOMs():
from sklearn import datasets
from minisom import MiniSom
d = datasets.load_iris()
data = np.apply_along_axis(lambda x: x/np.linalg.norm(x), 1, d['data']) # data normalization
som = MiniSom(7, 7, 4, sigma=1.0, learning_rate=0.5)
som.random_weights_init(data)
print("Training...")
som.train_random(data, 1000) # random training
print("\n...ready!")
### Plotting the response for each pattern in the iris dataset ###
from pylab import plot,axis,show,pcolor,colorbar,bone
bone()
pcolor(som.distance_map().T) # plotting the distance map as background
colorbar()
t = d['target']
# use different colors and markers for each label
markers = ['o','s','D']
colors = ['r','g','b']
for cnt,xx in enumerate(data):
w = som.winner(xx) # getting the winner
# 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)
axis([0,som.weights.shape[0],0,som.weights.shape[1]])
show() # show the figure
示例4: print
# 需要导入模块: from minisom import MiniSom [as 别名]
# 或者: from minisom.MiniSom import distance_map [as 别名]
data = numpy.nan_to_num(data)
print (data)
data = apply_along_axis(lambda x: x/linalg.norm(x),1,data) # data normalization
### Initialization and training ###
som = MiniSom(40,40,136,sigma=1.0,learning_rate=0.5)
som.random_weights_init(data)
print("Training...")
som.train_random(data,10000) # random training
print("\n...ready!")
### Plotting the response for each pattern in the iris dataset ###
from pylab import plot,axis,show,pcolor,colorbar,bone
bone()
pcolor(som.distance_map().T) # plotting the distance map as background
colorbar()
target = genfromtxt('class5.csv',delimiter=',',usecols=(0),dtype=int) # loadingthe labels
t = zeros(len(target),dtype=int)
print (target)
t[target == 0] = 0
t[target == 1] = 1
t[target == 2] = 2
t[target == 3] = 3
t[target == 4] = 4
t[target == 5] = 5
t[target == 6] = 6
t[target == 7] = 7
t[target == 8] = 8
示例5: MinMaxScaler
# 需要导入模块: from minisom import MiniSom [as 别名]
# 或者: from minisom.MiniSom import distance_map [as 别名]
# Feature Scaling
from sklearn.preprocessing import MinMaxScaler
sc = MinMaxScaler(feature_range = (0, 1))
X = sc.fit_transform(X)
# Training the SOM
from minisom import MiniSom
som = MiniSom(x = 10, y = 10, input_len = 15, sigma = 1.0, learning_rate = 0.5)
som.random_weights_init(X)
som.train_random(data = X, num_iteration = 100)
# Visualizing the results
from pylab import bone, pcolor, colorbar, plot, show
bone()
pcolor(som.distance_map().T)
colorbar()
markers = ['o', 's']
colors = ['r', 'g']
for i, x in enumerate(X):
w = som.winner(x)
plot(w[0] + 0.5,
w[1] + 0.5,
markers[y[i]],
markeredgecolor = colors[y[i]],
markerfacecolor = 'None',
markersize = 10,
markeredgewidth = 2)
show()
# Finding the frauds
示例6: SomPage
# 需要导入模块: from minisom import MiniSom [as 别名]
# 或者: from minisom.MiniSom import distance_map [as 别名]
class SomPage(tk.Frame):
## UI 생성
def __init__(self, parent, controller):
## tk.Frame 초기화
tk.Frame.__init__(self, parent)
style.use("ggplot")
self.figure = pl.figure(1)
self.a = self.figure.add_subplot(111)
self.canvas = FigureCanvasTkAgg(self.figure, self)
self.canvas.get_tk_widget().grid(sticky="news")
self.canvas._tkcanvas.grid(sticky="news")
## Initialization
self.som = MiniSom(10,10,136,sigma=1.0,learning_rate=0.5)
####---------------------------------------------
## THREAD 생성
def callback_threaded(self, status):
self.queue = Queue() # 크기가 1인 버퍼
self.thread = Thread(target=self.training, args=(status,))
self.thread.daemon = True
self.thread.start()
self.queue.put(object()) ## 첫번째
print("Start")
self.queue.join() ## 네번째
self.thread.join()
self.plotting(status)
## size, learning_rate, training_count, target_count)
def training(self, status):
self.figure.clear()
self.queue.get() ## 두번째
## reading the dataset in the csv format
self.data = genfromtxt('iris6.csv', delimiter=',',dtype = float)
self.data = numpy.nan_to_num(self.data)
## data normalization
self.data = apply_along_axis(lambda x: x/linalg.norm(x),1,self.data)
self.som.random_weights_init(self.data)
print("Training...")
self.som.train_random(self.data,100) # random training
bone()
## plotting the distance map as background
pcolor(self.som.distance_map().T)
colorbar()
## loadingthe labels
target = genfromtxt('iris4_2.csv', delimiter=',', usecols=(0), dtype=int)
self.t = zeros(len(target),dtype=int)
print("...ready to plot...")
for i in range(len(target)):
self.t[target == i] = i
self.som.win_map(self.data)
self.queue.task_done() ## 세번째
def plotting(self, status):
self.figure = pl.figure(1)
self.a = self.figure.add_subplot(111)
print("Plotting...")
## use differet colors and markers for each label
## markers = []
colors = ['r','g','b','y','w','orange','black','pink','brown','purple']
## making bm file
with open('bm.txt', 'w') as f:
f.write(str(len(self.data))+'\n')
for cnt,xx in enumerate(self.data):
win = self.som.winner(xx) # getting the winner
# palce a marker on the winning position for the sample xx
self.a.plot(win[0]+.5,win[1]+.5,'.', markerfacecolor='None', markeredgecolor=colors[self.t[cnt]], markersize=1, markeredgewidth=1)
f.write(str(win[0])+'\t'+str(win[1])+'\t'+str(self.t[cnt])+'\n')
## making umx file
with open('umx.txt', 'w') as f:
for cnt,xx in enumerate(self.data):
win = self.som.winner(xx) # getting the winner
# palce a marker on the winning position for the sample xx
self.a.plot(win[0]+.5,win[1]+.5,'.',markerfacecolor='None',
markeredgecolor=colors[self.t[cnt]], markersize=1, markeredgewidth=1)
#.........这里部分代码省略.........