機械学習の辞書学習DictionaryLearning

1363 ワード

  • 機械学習の辞書学習DictionaryLearning
  • # -*- coding: utf-8 -*-
    """
    Created on Sun Dec  9 13:00:52 2018
    
    @author: muli
    """
    
    from sklearn.decomposition import DictionaryLearning
    
    def test_DictionaryLearning():
        '''
          DictionaryLearning  
    
        :return: None
        '''
        X=[[1,2,3,4,5],
           [6,7,8,9,10],
           [10,9,8,7,6,],
           [5,4,3,2,1] ]
        print("before transform:",X)
        dct=DictionaryLearning(n_components=3)
        dct.fit(X)
        print("components is :
    ",dct.components_) print("after transform:
    ",dct.transform(X)) if __name__=='__main__': test_DictionaryLearning() # test_DictionaryLearning
  • X-B・Aを検証した結果
  • 
    import numpy as np
    
    A= [[  0.     ,      0.    ,      -7.39987319],
     [  0.          , 0.       ,  -17.80675663],
     [-18.16560383  , 0.       ,    0.        ],
     [  0.        ,  -7.41619849 ,  0.        ]]
    
    
    B=[[-0.5473499 , -0.49408716 ,-0.44082441, -0.38756166, -0.33429892],
     [-0.67419986 ,-0.53935989 ,-0.40451992, -0.26967994, -0.13483997],
     [-0.18512671 ,-0.30070103, -0.41627534, -0.53184965 ,-0.64742396]]
    
    
    #C=np.dot(A,np.transpose(B))
    #C=np.dot(np.transpose(B),np.transpose(A)).
    C=np.dot(A,B)
    
    print(C)
    
    
  • pythonによって生成された辞書Bは、本に定義された辞書Bと、転置関係がある可能性があることに注意する.