Ejemplo n.º 1
0
    def run(self):
        """
        :returns: Tuple, such as (<dict of nmis, with algorithm names as keys >)
        """

        nsc = NSpecSparse(self.X, self.k, maxiter=2000)
        nmf = NMF(self.X, self.k)
        km = KMeans(n_clusters=self.k)
        nsckm = NSpecSparseKM(self.X, self.k, maxiter=2000)

        nsc_result = nsc.predict()
        nmf_result = nmf.predict()
        km_result = km.fit_predict(self.X)
        nsckm_result = nsckm.predict()

        w_nsc = nsc_result.matrices[0].todense()
        w_nmf = nmf_result.matrices[0]
        w_nsckm = nsckm_result.matrices  # gets only the labels

        arrays = {
            'nsc': np.array(np.argmax(w_nsc, axis=1))[:, 0],
            'nmf': np.array(np.argmax(w_nmf, axis=1)),
            'km': km_result,
            'nsckm': w_nsckm
        }

        nmi = {k: nmiscore(arrays[k], self.y) for k in arrays.keys()}

        return (nmi, arrays)
Ejemplo n.º 2
0
    def run(self):
        """
        :returns: Tuple, such as (<dict of nmis, with algorithm names as keys >)
        """

        nsc = NSpecSparse(self.X, self.k, maxiter=2000)
        nmf = NMF(self.X, self.k)
        km = KMeans(n_clusters=self.k)
        nsckm = NSpecSparseKM(self.X, self.k, maxiter=2000)

        nsc_result = nsc.predict()
        nmf_result = nmf.predict()
        km_result  = km.fit_predict(self.X)
        nsckm_result = nsckm.predict()

        w_nsc = nsc_result.matrices[0].todense()
        w_nmf = nmf_result.matrices[0]
        w_nsckm = nsckm_result.matrices # gets only the labels

        arrays = {
            'nsc': np.array(np.argmax(w_nsc, axis=1))[:,0],
            'nmf': np.array(np.argmax(w_nmf, axis=1)),
            'km': km_result,
            'nsckm': w_nsckm
        }

        nmi = {k: nmiscore(arrays[k], self.y) for k in arrays.keys()}

        return (nmi, arrays)
Ejemplo n.º 3
0
def main():
    origin,mask = load_data(4,5,0.2)
    dm = origin*mask
    mask1 = dm / origin
    print(mask1)
    print(mask)
    nmf = NMF()
    rec = nmf.predict(dm,mask)
    print(rec-dm)
Ejemplo n.º 4
0
# encoding: utf-8
'''
Created on 2016年11月15日

@author: alibaba
'''
import numpy as np
#from basenmf import BaseNMF, NMFResult
#from projective import ProjectiveNMF
from nmf import NMF

X=np.array([(1,2,3,4,5,6),(4,5,6,7,8,9),(1,3,5,4,2,6)])/10.0
nmf=NMF(X,2,maxiter=100)
nmf_result=nmf.predict()
w_nmf = nmf_result.matrices[0]
print(w_nmf)