资源简介
自己用Python实现的PCA算法。Python3可直接导入数据运行。
代码片段和文件信息
#! /usr/local/bin/python3.6
# coding=utf-8
# 作者:huwenhao
# Github主页: https://github.com/huwenhao1127/
import numpy as np
import os
np.set_printoptions(threshold=np.inf)
os.environ[‘TF_CPP_MIN_LOG_LEVEL‘] = ‘2‘
# PCA(principal component analysis)
# data: raw data
# K: new dimensions
def pca(data k):
X = np.asmatrix(data)
RawDim NumData = data.shape[0] data.shape[1]
# Make X a mean-normalized m*n data matrix
for i in range(RawDim):
X[i] = X[i] - X[i].mean()
# Compute symmetric matrix of X
C = X*X
评论
共有 条评论