ValueError: X needs to contain only non-negative integers.
for feature in short_cate_feature:
enc.fit(data[feature].values.reshape(-1, 1))
base_train_csr = sparse.hstack((base_train_csr, enc.transform(train_x[feature].values.reshape(-1, 1))), 'csr','bool')
base_predict_csr = sparse.hstack((base_predict_csr, enc.transform(predict[feature].values.reshape(-1, 1))),'csr','bool')
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
报错:ValueError: X needs to contain only non-negative integers.
x不能包含负整数,因为我前面fillna(-1),
可以对dataframe,直接使用
for i in short_cate_feature:
all_table[i] = all_table[i].astype(str) 但是因为是独热码,需要非负整数。
因此用了个骚操作:
for i in short_cate_feature:
data[i] = data[i].map(dict(zip(data[i].unique(), range(0, data[i].nunique()))))
通过词典映射为数字
ValueError: X needs to contain only non-negative integers.的更多相关文章
- python 之 random.sample() 报ValueError: Sample larger than population or is negative
def device_id(): device = ''.join(random.sample(string.digits, 19)) return device print(device_id()) ...
- [Algorithm] Count Negative Integers in Row/Column-Wise Sorted Matrix
// Code goes here function countNegative (M, n, m) { count = ; i = ; j = m - ; && i < n) ...
- Interleaving Positive and Negative Numbers
Given an array with positive and negative integers. Re-range it to interleaving with positive and ne ...
- [LintCode] Interleaving Positive and Negative Numbers
Given an array with positive and negative integers. Re-range it to interleaving with positive and ne ...
- Lintcode: Interleaving Positive and Negative Numbers 解题报告
Interleaving Positive and Negative Numbers 原题链接 : http://lintcode.com/zh-cn/problem/interleaving-pos ...
- Twisted源码分析系列01-reactor
转载自:http://www.jianshu.com/p/26ae331b09b0 简介 Twisted是用Python实现的事件驱动的网络框架. 如果想看教程的话,我觉得写得最好的就是Twisted ...
- python,random随机数的获取
随机数生成 首先我们需要在程序中引入random>>>import random as r r.random()用于生成一个随机的浮点数, >>> print(r. ...
- 常见模块(五) random模块
random随机函数中的常用方法 1.random.random 返回一个介于左闭右开[0.0, 1.0)区间的浮点数 print(random.random()) 2.random.randrang ...
- python模块:random
"""Random variable generators. integers -------- uniform within range sequences ----- ...
- 使用python 模仿mybinlog 命令 二进制分析mysql binlog
出处:黑洞中的奇点 的博客 http://www.cnblogs.com/kelvin19840813/ 您的支持是对博主最大的鼓励,感谢您的认真阅读.本文版权归作者所有,欢迎转载,但请保留该声明. ...
随机推荐
- 素数筛 : Eratosthenes 筛法, 线性筛法
这是两种简单的素数筛法, 好不容易理解了以后写篇博客加深下记忆 首先, 这两种算法用于解决的问题是 : 求小于n的所有素数 ( 个数 ) 比如 这道题 在不了解这两个素数筛算法的同学, 可能会这么写一 ...
- 02.DRF-认识RESTful
认识RESTful 在前后端分离的应用模式里,后端API接口如何定义? 例如对于后端数据库中保存了商品的信息,前端可能需要对商品数据进行增删改查,那相应的每个操作后端都需要提供一个API接口: POS ...
- CSS中 隐藏元素的常用方法
在CSS中,使某个元素在页面中消失的方法有很多,今天为大家介绍几种我常用的方式 . 一.display:none; 让元素直接从页面消失,不占用尺寸,会改变页面布局. 代码演示: 页面演示:在页面 ...
- selenium(4)-针对键盘的操作
有哪些键盘操作 删除键 空格键 制表键 回退键 回车键 全选 复制 剪切 粘贴 F1-F12 ......其实就是所有键盘都能模拟,包括alt.shift.insert.delete.home等等等. ...
- .Net Core Configuration源码探究
前言 上篇文章我们演示了为Configuration添加Etcd数据源,并且了解到为Configuration扩展自定义数据源还是非常简单的,核心就是把数据源的数据按照一定的规则读取到指定的字 ...
- oracle不足位数补零的实现sql语句
select rpad('AAA',5,'0') from dual; 这样就可以了 [注意] 1.'AAA'为待补字符:5表示补齐后的总字符长度:0表示不足时补什么字符 2.rpad是右侧补0,左侧 ...
- 全链路监控系统开源Pinpoint入门视频教程(最新版本1.8)
pinpoint支持的模块 源码:https://github.com/naver/pinpoint技术概述:https://skyao.gitbooks.io/learning-pinpoint/c ...
- mysql语句基本练习
select ename,job from emp where job in ('MANAGER','ANALYET','SALESMAN') 1.查询出工作岗位为MANAGER.ANALYST.SA ...
- Java是如何实现Future模式的?万字详解!
JDK1.8源码分析项目(中文注释)Github地址: https://github.com/yuanmabiji/jdk1.8-sourcecode-blogs 1 Future是什么? 先举个例子 ...
- Java笔试面试总结—try、catch、finally语句中有return 的各类情况
前言 之前在刷笔试题和面试的时候经常会遇到或者被问到 try-catch-finally 语法块的执行顺序等问题,今天就抽空整理了一下这个知识点,然后记录下来. 正文 本篇文章主要是通过举例的方式来阐 ...