独热向量编码原理

`# -- coding: utf-8 --
from future import unicode_literals
import numpy as np
import sklearn.preprocessing as sp

raw_samples = np.array([
[1, 3, 2],
[7, 5, 4],
[1, 8, 6],
[7, 3, 9]])
print(raw_samples)

底层原理

code_tables = []
先创建一个字典,来保存原始数据,编译的结果数据,用键值对来表示最好
一个列一个字典,那么就是一个字典列表了
for col in raw_samples.T:
code_table = {}
for val in col:
code_table[val] = None
code_tables.append(code_table)

给字典取值
for code_table in code_tables:
size = len(code_table)
for one, key in enumerate(sorted(code_table.keys())):
code_table[key] = np.zeros(shape=size, dtype=int)
code_table[key][one] = 1
ohe_samples = []
下面用到了列表里面嵌套列表
开始编码
for raw_sample in raw_samples:
ohe_sample = np.array([], dtyp

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值