Skip to content
Snippets Groups Projects
Commit ead4c43f authored by DIANE's avatar DIANE
Browse files

pca update

parent 7988d10c
No related branches found
No related tags found
No related merge requests found
from Packages import *
from Class_Mod.DATA_HANDLING import *
from sklearn.decomposition import PCA
class LinearPCA:
def __init__(self, X, Ncomp=10):
......@@ -57,12 +55,15 @@ class LinearPCA:
Hat = ti @ np.linalg.pinv(np.transpose(ti) @ ti) @ np.transpose(ti)
self.lev[self._r.columns[i]] = ti.ravel()
self.leverage = pd.DataFrame(self.lev)
## Hotelling t2
#self.eigvals = M.singular_values_**2
#self.Lambda = np.diag(self.eigvals)
#self.T2 = self.__t @ np.linalg.inv(self.Lambda) @self.__t.T
## Hotelling t2
self.eigvals = M.singular_values_**2
self.Lambda = np.diag(self.eigvals)
self.T2 = pd.DataFrame()
tt = self._r.to_numpy()
for i in range(self._t.shape[1]):
self.T2[self.__pcnames[i]] = np.diag(self.__t[:,i].reshape((-1,1)) @ np.linalg.inv(np.array(self.Lambda[i,i]).reshape((1,1))) @ np.transpose(self.__t[:,i].reshape((-1,1))))
@property
......@@ -79,4 +80,8 @@ class LinearPCA:
@property
def residuals(self):
return self.res
\ No newline at end of file
return self.res
@property
def hotelling(self):
#return pd.DataFrame(self.T2)
return self.T2
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment