当前位置: 首页>>代码示例>>Python>>正文


Python MiniSom.train_random方法代码示例

本文整理汇总了Python中minisom.MiniSom.train_random方法的典型用法代码示例。如果您正苦于以下问题:Python MiniSom.train_random方法的具体用法?Python MiniSom.train_random怎么用?Python MiniSom.train_random使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在minisom.MiniSom的用法示例。


在下文中一共展示了MiniSom.train_random方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testSOMs

# 需要导入模块: from minisom import MiniSom [as 别名]
# 或者: from minisom.MiniSom import train_random [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
开发者ID:eddienko,项目名称:EuclidVisibleInstrument,代码行数:32,代码来源:SOM.py

示例2: SOM

# 需要导入模块: from minisom import MiniSom [as 别名]
# 或者: from minisom.MiniSom import train_random [as 别名]
def SOM(data,leninput,lentarget):
    som = MiniSom(16,16,leninput,sigma=1.0,learning_rate=0.5)
    som.random_weights_init(data)
    print("Training...")
    som.train_random(data,10000) # training with 10000 iterations
    print("\n...ready!")
    
    numpy.save('weight_som',som.weights)
开发者ID:NurFaizin,项目名称:Combining-Web-Content-and-Usage-Mining,代码行数:10,代码来源:app.py

示例3: _minisomrandom

# 需要导入模块: from minisom import MiniSom [as 别名]
# 或者: from minisom.MiniSom import train_random [as 别名]
    def _minisomrandom(self):
        """Clusters sentence vectors using minisomrandom algorithm
        
        Returns
        -------
        numpy ndarray
            codebook (weights) of the trained SOM
        """

        H = int(self.opts['size'])
        W = int(self.opts['size'])
        N = self.X.shape[1]
        som = MiniSom(H, W, N, sigma=1.0, random_seed=1)
        if self.opts['initialization']:
            som.random_weights_init(self.X)
        som.train_random(self.X, self.opts['niterations'])
        return som.get_weights()
开发者ID:avsilva,项目名称:sparse-nlp,代码行数:19,代码来源:sentencecluster.py

示例4: train_som

# 需要导入模块: from minisom import MiniSom [as 别名]
# 或者: from minisom.MiniSom import train_random [as 别名]
def train_som(data, offset=None):
    """
    offset: offset between points used for training
    """
    
    if offset:
        data = data[::offset, :]
    
    som = MiniSom(
        param['nr_rows'],
        param['nr_cols'], 
        data.shape[1], 
        data, 
        sigma=param['sigma'], 
        learning_rate=param['learning_rate'], 
        norm='minmax')
        
    #som.random_weights_init() # choose initial nodes from data points
    som.train_random(param['nr_epochs']) # random training
    
    return som
开发者ID:ikajic,项目名称:cogrob-pointing,代码行数:23,代码来源:minisom_nao.py

示例5: learn

# 需要导入模块: from minisom import MiniSom [as 别名]
# 或者: from minisom.MiniSom import train_random [as 别名]
def learn(dataset,sigma=0.3,learning_rate=0.5,nb_iter=10000):
	nb_sample, nb_features = dataset.shape
	som = MiniSom(6,6,nb_features,sigma=sigma,learning_rate=learning_rate)
	som.train_random(dataset,nb_iter)
	return som
开发者ID:slimaku,项目名称:hesso.mlbd.deckfinder,代码行数:7,代码来源:som.py

示例6: imread

# 需要导入模块: from minisom import MiniSom [as 别名]
# 或者: from minisom.MiniSom import train_random [as 别名]
from pylab import imread,imshow,figure,show,subplot,title
from numpy import reshape,flipud,unravel_index,zeros
from minisom import MiniSom

# read the image
img = imread('tree.jpg')

# reshaping the pixels matrix
pixels = reshape(img,(img.shape[0]*img.shape[1],3))

# SOM initialization and training
print('training...')
som = MiniSom(3,3,3,sigma=0.1,learning_rate=0.2) # 3x3 = 9 final colors
som.random_weights_init(pixels)
starting_weights = som.weights.copy() # saving the starting weights
som.train_random(pixels,100)

print('quantization...')
qnt = som.quantization(pixels) # quantize each pixels of the image
print('building new image...')
clustered = zeros(img.shape)
for i,q in enumerate(qnt): # place the quantized values into a new image
	clustered[unravel_index(i,dims=(img.shape[0],img.shape[1]))] = q
print('done.')

# show the result
figure(1)
subplot(221)
title('original')
imshow(flipud(img))
subplot(222)
开发者ID:JaySquare87,项目名称:minisom,代码行数:33,代码来源:example_color.py

示例7: MinMaxScaler

# 需要导入模块: from minisom import MiniSom [as 别名]
# 或者: from minisom.MiniSom import train_random [as 别名]
# Importing the dataset
dataset = pd.read_csv('Credit_Card_Applications.csv')
X = dataset.iloc[:, :-1].values
y = dataset.iloc[:, -1].values

# 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',
开发者ID:kmrskt,项目名称:fraud_detection_using_som,代码行数:32,代码来源:som.py

示例8: _parse_file_argument

# 需要导入模块: from minisom import MiniSom [as 别名]
# 或者: from minisom.MiniSom import train_random [as 别名]
    plt.pcolor(som.distance_map().T)

    return fig, ax

RS = 20160101

if __name__ == '__main__':
    args = _parse_file_argument()
    data = pd.read_csv(args.csv)
    data.fillna(0, inplace=True)

    label_column = args.label_prefix
    label_prefix = data[label_column].values
    data.drop(label_column, axis=1, inplace=True)

    label_column = args.label_sufix
    label_sufix = data[label_column].values
    data.drop(label_column, axis=1, inplace=True)

    id_column = 'id'
    data.drop(id_column, axis=1, inplace=True)

    som = MiniSom(8,8,len(data.columns),sigma=1.0,learning_rate=0.5,random_seed=RS)
    som.random_weights_init(data.as_matrix())

    som.train_random(data.as_matrix(),100)

    _plot_distribution(som)
    plt.savefig('som.png', dpi=120)
开发者ID:maiteb,项目名称:som-python,代码行数:31,代码来源:som.py

示例9: If_running

# 需要导入模块: from minisom import MiniSom [as 别名]
# 或者: from minisom.MiniSom import train_random [as 别名]

#.........这里部分代码省略.........

	# use different colors and markers for each label
	markers = ['o','s','D', '+']
	colors = ['r','g','b', 'y']
	for cnt,xx in enumerate(data):
	  w = self.som.winner(xx) # getting the winner
	  # place a marker on the winning position for the sample xx
	  tmp = self.axes.plot(w[0]+.5,w[1]+.5,markers[t[cnt]],markerfacecolor='None',
	      markeredgecolor=colors[t[cnt]],markersize=12,markeredgewidth=2)
	self.axes.axis([0,self.som.weights.shape[0],0,self.som.weights.shape[1]])
	#show() # show the figure
	#print "drawing"
	#self.figure.canvas.draw()



    def init_som(self, widget=None, data=None):
      ##print self.data
      ### Initialization and training ###
      cols = self.columns[self.combobox.get_active()]
      data = self.data[:, 0:len(cols)]

      #print len(cols)
      self.som = MiniSom(self.width_spin_button.get_value_as_int(), self.height_spin_button.get_value_as_int(), len(cols),sigma=1.2,learning_rate=0.5)
#      self.som.weights_init_gliozzi(data)
      self.som.random_weights_init(data)

    def train_som(self):
      cols = self.columns[self.combobox.get_active()]
      data = self.data[:, 0:len(cols)]
      print("Training...")
      #self.som.train_gliozzi(data) # Gliozzi et al training

      self.som.train_random(data,20)


      print("\n...ready!")

    def make_treeview(self, data, liststore):
	#i = 0
	cols = self.columns[self.combobox.get_active()]
	#print type(cols)
	#print len(cols)
	for d in data:
	  #i += 1

	  tmp = d.tolist()
	  #print 'tmp', tmp
	  #while len(tmp) < cols:
	    #tmp.append(False)
	    #print 'tmp', tmp
	    #cols = cols - 1
	  Qe = MiniSom.quantization_error_subset(self.som,d,len(cols))
	  #print tmp
	  tmp.append(Qe)
	  tmp.append(4 * Qe ** 0.5)
	  liststore.append(tmp)

	treeview = gtk.TreeView(model=liststore)
	#i = 0
	for d in range(len(self.test_data[0])):
	  #print i
	  #i += 1
	  renderer_text = gtk.CellRendererText()
	  column_text = gtk.TreeViewColumn(self.pattern_labels[d], renderer_text, text=d)
	  treeview.append_column(column_text)
开发者ID:sriveravi,项目名称:som,代码行数:70,代码来源:gui.py

示例10: MiniSom

# 需要导入模块: from minisom import MiniSom [as 别名]
# 或者: from minisom.MiniSom import train_random [as 别名]
model = Doc2Vec.load("../model/doc_model.mod")
doc_labels = random.sample(model.docvecs.doctags.keys(), 4000)

#### selection 
doc_vecs = []
for label in doc_labels:
	doc_vecs += [model.docvecs[label]]
doc_vecs = np.array(doc_vecs)

####

print "Clustering..."
N_CLUSTERS = 4
som = MiniSom(4, 4, 64, sigma=0.3, learning_rate=0.5)
som.train_random(doc_vecs, 100)
qnt = som.quantization(doc_vecs)

uniques = []
for i in qnt:
	has_it = False
	for elem in uniques:
		if np.array_equal(elem, i):
			has_it = True
	if not has_it:
		uniques += [i]

####

def get_similar_words(doc):
	score_dict = {}
开发者ID:PragmaticLab,项目名称:w2v_to_d2v,代码行数:32,代码来源:som.py

示例11: len

# 需要导入模块: from minisom import MiniSom [as 别名]
# 或者: from minisom.MiniSom import train_random [as 别名]

# reading the iris dataset in the csv format    
# (downloaded from http://aima.cs.berkeley.edu/data/iris.csv)
#rn = len(open('iris4.csv').readlines())

data = genfromtxt('data5.csv', delimiter=',',dtype = float)
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
开发者ID:heeju00627,项目名称:heeju,代码行数:32,代码来源:mytest(som).py

示例12: load_mPD

# 需要导入模块: from minisom import MiniSom [as 别名]
# 或者: from minisom.MiniSom import train_random [as 别名]
  PD
  ProtNames
except:
  mPD = load_mPD()
  PD,ProtNames = load_PD()

R = Cluster.somcluster(mPD,transpose=1,nxgrid=40,nygrid=40,niter=1)

from minisom import MiniSom
### Initialization and training ###
som = MiniSom(40,40,15,sigma=1.0,learning_rate=0.5)
#som.random_weights_init(mPD)
som.weights
som.random_weights_init(transpose(mPD))
print("Training...")
som.train_random(transpose(mPD),100) # training with 100 iterations
print("\n...ready!")


timg = np.zeros(shape=(40,40))
for c in R[0]:
  timg[c[0],c[1]]=timg[c[0],c[1]]+1


plt.figure()
plt.subplot(2,2,1)
plt.imshow(R[1][:,:,1])
plt.subplot(2,2,2)
plt.imshow(mean(R[1],axis=2))
plt.colorbar()
plt.subplot(2,2,3)
开发者ID:eugenpt,项目名称:ICG_bioinfo_stuff,代码行数:33,代码来源:ep_bioinfo_somTest.py

示例13: MiniSom

# 需要导入模块: from minisom import MiniSom [as 别名]
# 或者: from minisom.MiniSom import train_random [as 别名]
tacitus = pickle.load(f)
f.close()

print "loaded data core"
data = tacitus.cv_21
num = tacitus.cv_21w
n_samples, n_features = data.shape
######################################

# Functional Code Below:
if mode == 1:
    print "Using SOM"
    drmap = MiniSom(50,50,6,sigma=.8,learning_rate=.5) # Replace 64 with the dimensions of desired target (6)
    if fresh_data == 1:
        print "Training..."
        drmap.train_random(data,1500) # random training
        print "\n...ready!"
    elif fresh_data == 0:
        print "Loading Data"
        drmap.load_map()

    # plotting the results
    from pylab import text,show,cm,axis,figure,subplot,imshow,zeros
    figure(1)
    im = 0
    result = np.array([])
    for x,t in zip(data,num): # scatterplot
     w = drmap.winner(x)
     result.resize((im+1,3))
     result[im][0]=w[0]
     result[im][1]=w[1]
开发者ID:mrich7,项目名称:hrl-summer-2014,代码行数:33,代码来源:dr.py

示例14: SomPage

# 需要导入模块: from minisom import MiniSom [as 别名]
# 或者: from minisom.MiniSom import train_random [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)
#.........这里部分代码省略.........
开发者ID:heeju00627,项目名称:heeju,代码行数:103,代码来源:class_som.py

示例15: MiniSom

# 需要导入模块: from minisom import MiniSom [as 别名]
# 或者: from minisom.MiniSom import train_random [as 别名]
import numpy as np 
from minisom import MiniSom

data = np.genfromtxt('isolet1+2+3+4.data', delimiter=',')

label = data[:,617]
data = data[:,0:617]
data = np.apply_along_axis(lambda x: x/np.linalg.norm(x),1,data)

som = MiniSom(10,10,617,sigma=1.0, learning_rate=0.5)

som.random_weights_init(data)
original_error = som.quantization_error(data)
print original_error

som.train_random(data, 5000)
print som.quantization_error(data)

### graphing
from pylab import plot,axis,show,pcolor,colorbar,bone
import random 

indexes = random.sample(range(0, len(label)), 500)
graph_target = label[indexes]
graph_data = data[indexes,]

t = np.zeros(len(graph_target),dtype=int)
# everything starts as 0
t[graph_target == 12] = 1
t[graph_target == 2] = 2
开发者ID:gnperdue,项目名称:Quick-Data-Science-Experiments-2016,代码行数:32,代码来源:isolet.py


注:本文中的minisom.MiniSom.train_random方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。