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.的更多相关文章

  1. 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()) ...

  2. [Algorithm] Count Negative Integers in Row/Column-Wise Sorted Matrix

    // Code goes here function countNegative (M, n, m) { count = ; i = ; j = m - ; && i < n) ...

  3. Interleaving Positive and Negative Numbers

    Given an array with positive and negative integers. Re-range it to interleaving with positive and ne ...

  4. [LintCode] Interleaving Positive and Negative Numbers

    Given an array with positive and negative integers. Re-range it to interleaving with positive and ne ...

  5. Lintcode: Interleaving Positive and Negative Numbers 解题报告

    Interleaving Positive and Negative Numbers 原题链接 : http://lintcode.com/zh-cn/problem/interleaving-pos ...

  6. Twisted源码分析系列01-reactor

    转载自:http://www.jianshu.com/p/26ae331b09b0 简介 Twisted是用Python实现的事件驱动的网络框架. 如果想看教程的话,我觉得写得最好的就是Twisted ...

  7. python,random随机数的获取

    随机数生成 首先我们需要在程序中引入random>>>import random as r r.random()用于生成一个随机的浮点数, >>> print(r. ...

  8. 常见模块(五) random模块

    random随机函数中的常用方法 1.random.random 返回一个介于左闭右开[0.0, 1.0)区间的浮点数 print(random.random()) 2.random.randrang ...

  9. python模块:random

    """Random variable generators. integers -------- uniform within range sequences ----- ...

  10. 使用python 模仿mybinlog 命令 二进制分析mysql binlog

    出处:黑洞中的奇点 的博客 http://www.cnblogs.com/kelvin19840813/ 您的支持是对博主最大的鼓励,感谢您的认真阅读.本文版权归作者所有,欢迎转载,但请保留该声明. ...

随机推荐

  1. Vue —— 精讲 VueRouter(1)

    最近被Boos调去给新人做培训去了,目前把自己整理的一些东西分享出来,希望对大家有所帮助 本章节为VueRouter前端 路由的章节部分 大纲 一.基本概念 路由就是通过网络把讯息从源地址传输到目的地 ...

  2. 快捷键浏览存储过程的内容(执行文中的User Store Proc,设置快捷方式的指向usp_Name)

    虽然不常用,但使用时还是在用传统方法查看存储过程的内容, sp_helptext usp_Name;下面这段执行后可设置快捷查询usp的内容(但是需要在每个数据库下都存在,不能直接在master,并且 ...

  3. Python变量和注释

    1.变量与变量的作用: (1)什么是变量:变量源于数学,是计算机语言中能存储计算结果或能表示值抽象概念.变量可以通过变量名访问.在指令式语言中,变量通常是可变的:在Python中变量名必须是大小写英文 ...

  4. controller场景设计

    场景设计模型-手动场景快增长慢增长指定运行次数组模式 快增长模型:就是压力瞬间启动并且达到最大,通常用于秒杀的场景 loadrunner设置:瞬间启动,瞬间停止 慢增长:压力按照设定的规则慢慢的添加, ...

  5. c常用函数-strchr和strrchr

    strchr和strrchr strrchr函数用于查找指定字符在一个字符串中最后一次出现的位置,然后返回指向该位置的指针 strchr函数用于查找指定字符在一个字符串中第一次出现的位置,然后返回指向 ...

  6. v-forv-for指令的三种使用方法

    1.迭代数组 <p v-for="(item,i) in list">id:{{item.id}}---名字:{{item.name}}---索引{{item.age} ...

  7. Jmeter系列(27)- 详解正则提取器

    如果你想从头学习Jmeter,可以看看这个系列的文章哦 https://www.cnblogs.com/poloyy/category/1746599.html 有了 JSON 提取器为啥还要用正则提 ...

  8. 面试官:你精通多少种语言的 Hello World?

    Hello World,是程序员入门编程语言的第一课.不论是C.C++还是Java ,我们写的第一个程序就是它了,还记得小编在大一C语言课上,花了一整节课时间才把它打印到控制台上.万事开头难啊,相信看 ...

  9. vue全家桶(2.6)

    3.9.滚动行为 设置滚动行为的作用是导航到新路由时,让页面滚动到你想要的位置. const router = new VueRouter({ routes: [...], scrollBehavio ...

  10. 双缓冲显示字幕(卡拉ok字幕)

    思路: 1.设置定时器SetTime,在Ontime()里面确定显示矩形的大小,让后用DrawText把字铁道矩形上面: 2. int nTextHei = dc.GetTextExtent( m_s ...