def fit(self, X, y=None):
# X = array2d(X)
n_samples, n_features = X.shape
X = as_float_array(X, copy=self.copy)
# substracts the mean for each feature vector
self.mean_ = np.mean(X, axis=0)
X -= self.mean_
eigs, eigv = eigh(np.dot(X.T, X) / n_samples + \
self.bias * np.identity(n_features))
components = np.dot(eigv * np.sqrt(1.0 / eigs), eigv.T)
self.components_ = components
# Order the explained variance from greatest to least
self.explained_variance_ = eigs[::-1]
return self
评论列表
文章目录