LDA降维

feature_dict = {i:label for i,label in zip(range(4),('spepal length in cm','spepal width in cm','petal length in cm','petal width in cm'))}

import pandas as pd

df = pd.io.parsers.read_csv(filepath_or_buffer='链接(省略)',header=None,sep=',',)
df columns = [l for i,l in sorted(feature_dict.items())] + ['class label']
df.dropna(how="all",inplace=True)

df.tail()

映射:将y变成可衡量的数据格式

from
sklearn.preprocessing import LabelEncoder X = df[['spepal length in cm','spepal width in cm','petal length in cm','petal width in cm']].values y = df['class label'].values enc = LabelEncoder() label_encoder = enc.fit(y) y = label_encoder.transform(y) + 1

转化后的结果:
每类样例的均值:
import
numpy as np np.set_printoptions(precision=4) mean_vectors = [] for c1 in range(1,4): mean_vectors.append(np.mean(X[y==c1],axis=0) print('Mean vector class %s:%s\n'%(c1,mean_vectors[c1-1]))

 

转载于:https://www.cnblogs.com/panjie123pakho/p/7887498.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值