标签:tran product 类别 地址 tac cross and component 合并
import pandas as pd from sklearn.decomposition import PCA # 数据地址:https://www.kaggle.com/c/instacart-market-basket-analysis/data # 读取表 prior = pd.read_csv(r"E:\360Downloads\Software\降维案列数据\order_products__prior.csv") products = pd.read_csv(r"E:\360Downloads\Software\降维案列数据\products.csv") order = pd.read_csv(r"E:\360Downloads\Software\降维案列数据\order.csv") aisles = pd.read_csv(r"E:\360Downloads\Software\降维案列数据\aisles.csv") # 合并表,prodyct_id按该列合并 _mg = pd.merge(prior, products, on=[‘prodyct_id‘, ‘product_id‘]) _mg = pd.merge(_mg, order, on=[‘order_id‘, ‘order_id‘]) mt = pd.merge(_mg, aisles, on=[‘aisle_id‘, ‘aisle_id‘]) # 使用交叉表,构造用户-购买商品类别表 cross = pd.crosstab(mt[‘user_id‘], mt[‘aisle‘]) # 进行主成分分析,将冗余的商品类别过滤掉,即将少量或者几乎没有人购买的商品类别过滤掉 pca = PCA(n_components=0.9) data = pca.fit_transform(cross)
标签:tran product 类别 地址 tac cross and component 合并
原文地址:https://www.cnblogs.com/kogmaw/p/12571637.html