《python数据挖掘入门与实践》笔记1

1.导入iris植物数据集,包含150个sample。X是一个4元组,包含特征:sepal length、 sepal width、 petal length、 petal width。Y是每个sample的分类情况,分类有三种情况(0,1,2)表示。

from sklearn.datasets import load_iris
dataset=load_iris()
X=dataset.data
Y=dataset.target

2.将连续的数据离散化。以平均值做阈值。

attribute_mean= X.mean(axis=0)
X_d=np.array(X>=attribute_mean,dtype=’int’)

from collections import defaultdict
from operator import itemgetter

3.实现OneR算法。
X是特征集,y_ture是分类信息,feature_index表示用第几个特征来分类,value表示特征值。(zip()函数:将两个元组一一对应)
train_feature_value函数统计了y类中第feature_index个特征值为value的sample个数

def train_feature_value(X,y_true,feature_index,value):
class_counts=defaultdict(int)
for sample ,y in zip(X,y_true):
if sample[feature_index]==value:
class_counts[y]+=1

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值