微信公众号
关键字全网搜索最新排名
【机器学习算法】:排名第一
【机器学习】:排名第二
【Python】:排名第三
【算法】:排名第四
PCA前言
众所周知,PCA 的主要目的是降维,同时也可以起到分类的作用。当数据维度很大的时候,如果相信大部分变量之间存在线性关系,那么我们就希望降低维数,用较少的变量来抓住大部分的信息。(一般来讲做PCA 之前要做normalization 使得变量中心为0,而且方差为1.)比较广泛应用于图像识别,文档处理,推荐系统等。
PCA应用举例
推荐系统
如果一个旅游网站里面有10000000 个注册用户,以及100 个注册酒店. 网站有用户通过本网站点击酒店页面的记录信息.A = [Aij ]10000000100,Aij 表示第i 个用户点击j 酒店的次数.
问题:
如何评价酒店之间的相似度?
给定一个酒店,请找出与它最相似的其他几个酒店?
如果要给酒店分类,有什么办法?
生成100000x100的用户-酒店行为数据
import pandas as pd

import numpy as np
#prepare data set, suppose there are 5 types of hotels

generatorNum=5

hotelNum=100

customerNum=100000


generators = np.random.randint(5, size=(customerNum, generatorNum))

hotelComp=np.random.random(size=(generatorNum, hotelNum)) - 0.5

hotelRating = pd.DataFrame(generators.dot(hotelComp),index=['c%.6d'%i for i in range(100000)]

                         ,columns = ['hotel_%.3d'%j for j in range(100)]).astype(int)


def normalize(s):

   if s.std()>1e-6:

       return (s-s.mean())*s.std()**(-1)

   else:

       return (s-s.mean())

hotelRating数据如下所示。
hotelRating_norm = hotelRating.apply(normalize)

hotelRating_norm_corr = hotelRating_norm.cov()

hotelRating_norm_corr如下所示。
u,s,v = np.linalg.svd(hotelRating_norm_corr)

In [9]:
import matplotlib.pyplot as plt

plt.plot(s,'o')

plt.title("singular value spectrum")

plt.show()

In [10]:
u_short = u[:,:5]

v_short = v[:5,:]

s_short = s[:5]


hotelRating_norm_corr_rebuild = pd.DataFrame(u_short.dot(np.diag(s_short).dot(v_short))

                                           ,index=hotelRating_norm_corr.index

                                           ,columns=hotelRating_norm_corr.keys())

In [11]:
#get the top components

top_components = hotelRating_norm.dot(u_short).dot(np.diag(np.power(s_short,-0.5)))

In [12]:
#classfication of each hotel

hotel_ind = 30

rating = hotelRating_norm.loc[:,'hotel_%.3d'%hotel_ind]

print "classification of the %dth hotel"%hotel_ind

top_components.T.dot(rating)/customerNum

classification of the 30th hotel
0    0.136138

1    0.179586

2   -0.071347

3   -0.384475

4    0.647324

投稿、商业合作
请发邮件到:[email protected]
今年 7 月 7 日至 9 日的深圳,将迎来国内人工智能与机器人领域最重量级的行业盛会——CCF-GAIR 2017。这届由 CCF 主办与香港中文大学(深圳)举办的千人盛会将邀请全球范围内最优秀的学术专家、最顶尖的企业领袖,以及最炙手可热的明星创业团队与风险投资人莅临现场,为在场的观众们带来一场持续三天的饕餮盛宴。
【机器学习算法与Python学习】联合雷锋网,CCF-GAIR 2017 正在火热预售限量 200 张的六折门票,抢购这批门票的参会者可以享受与全价票同等的福利;此外还有 50 个 VIP 席位虚位以待,除了普通参会门票所享受的权益外,还为 VIP 嘉宾提供了贵宾区座位、VIP 午餐、「最佳 AI 雇主」及「新智造创新榜单」的两场晚宴入场券。可点击「阅读原文」了解更多信息。
继续阅读
阅读原文