def transform(self, X, y):
"""transform function"""
XMat = np.array(X)
yMat = np.array(y)
if XMat.shape[0] != yMat.shape[0]:
yMat = yMat.T
assert XMat.shape[0] == yMat.shape[0]
XMat -= XMat.mean(axis=0)
Sw, Sb = calc_Sw_Sb(XMat, yMat)
evals, evecs = eig(Sw, Sb)
np.ascontiguousarray(evals)
np.ascontiguousarray(evecs)
idx = np.argsort(evals)
idx = idx[::-1]
evecs = evecs[:, idx]
self.W = evecs[:, :self.n_components]
X_transformed = np.dot(XMat, self.W)
return X_transformed
评论列表
文章目录