One-hot编码:Python sklearn CTR实验
2014-05-03 15:10
330 查看
import numpy as np from sklearn.preprocessing import OneHotEncoder from numpy import * import MySQLdb conn = MySQLdb.connect(host='localhost', user='root', passwd='Zhouy2008', port = 3306) cursor = conn.cursor() # 选择该数据库 conn.select_db('ml_test') # 查询one_hot数据表中的数据 sql = "select * from one_hot" cursor.execute(sql) data = cursor.fetchall() print 'now, transfrom data type from tuple to ndarray' print 'data_arr:\n' data_arr = np.array(data) for i in data_arr: print i # one-hot编码过程 enc = OneHotEncoder() enc.fit(data_arr) data_hoted = enc.transform(data_arr).toarray() print print 'enc.transform(all).toarray():\n', enc.transform(data_arr).toarray() # 如何将data_hoted(数组形式)写入文本 num_rows, num_cols = shape(data_hoted) print '写入文本' f = open("G:/one_hoted.txt", "w") for i in range(num_rows): print >>f, data_hoted[i,:] f.close() print '写入文本完成'
相关文章推荐
- Verilog中状态机编码方式的选择:二进制编码(Binary)、格雷码(Gray-code)编码、独热码(One-hot)编码
- One-hot 编码/TF-IDF 值来提取特征,LAD/梯度下降法(Gradient Descent),Sigmoid
- 处理离散型特征和连续型特征共存的情况 归一化 论述了对离散特征进行one-hot编码的意义
- 【自用】 Pandas 预处理 —— 补全和编码(one-hot)
- Spark MLlib特征处理:OneHotEncoder OneHot编码 ---原理及实战
- one hot 编码及数据归一化
- Spark MLlib特征处理:OneHotEncoder OneHot编码 ---原理及实战
- python 中one—hot 三种编码方式
- Verilog中状态机编码方式的选择:二进制编码(Binary)、格雷码(Gray-code)编码、独热码(One-hot)编码
- pandas使用get_dummies进行one-hot编码的方法
- Verilog中状态机编码方式的选择:二进制编码(Binary)、格雷码(Gray-code)编码、独热码(One-hot)编码
- 对python sklearn one-hot编码详解
- one-hot编码(独热编码)
- pandas中one-hot编码的神坑
- 【QLBD】LSTM情感分析实验复现(二)分词&one-hot
- 常用计数器的verilog实现(binary、gray、one-hot、LFSR、环形、扭环形)
- one-hot coding(热独编码)
- TensorFlow 多分类标签转换成One-hot
- One Hot Code---独热码
- tf.one_hot()进行独热编码