机器学习笔记2-量化类别数据

本文主要探讨了机器学习中如何处理类别类数据,包括其重要性、常见类型以及常用的量化方法,为理解和应用提供基础。
摘要由CSDN通过智能技术生成

类别类数据:

from sklearn.preprocessing import LabelEncoder
from sklearn.preprocessing import OneHotEncoder

# TODO: Create a LabelEncoder object, which will turn all labels present in
#       in each feature to numbers. 
# HINT: Use LabelEncoder()
le = LabelEncoder()


# TODO: For each feature in X, apply the LabelEncoder's fit_transform
#       function, which will first learn the labels for the feature (fit)
#       and then change the labels to numbers (transform). 

for feature in X:
    # HINT: use fit_transform on X[feature] using the LabelEncoder() object
    le.fit(X[feature]) 
    X[feature] = le.transform(X[feature])# TODO
#print X
# TODO: Create a OneHotEncoder object, which will create a feature for each
#       label present in the data. 
# HINT: Use OneHotEncoder()
ohe = OneHotEncoder()

# TODO: Apply the 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值