Newer
Older
from Packages import *
class Nmf:
def __init__(self, X, Ncomp=3):
## input matrix
if np.min(X)<0:
self.__x = np.array(X-np.min(X))
else:
self.__x = np.array(X)
## set the number of components to compute and fit the model
self.__ncp = Ncomp
# Fit PCA model
Mo = NMF(n_components=self.__ncp, init=None, solver='cd', beta_loss='frobenius',
tol=0.0001, max_iter=300, random_state=None, alpha_W=0.0, alpha_H='same',
l1_ratio=0.0, verbose=0, shuffle=False)
Mo.fit(self.__x)
# Results
self._p = Mo.components_.T
self._t = Mo.transform(self.__x)
@property
def scores_(self):
return pd.DataFrame(self._t)
@property
def loadings_(self):
return pd.DataFrame(self._p)