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. Tensorflow中Tensor对象的常用方法(持续更新)

    Tensor是Tensorflow中重要的对象.下面是Tensor的常用方法,后面还会写一篇随笔记录Variable的用法. 1. 生成一个(常)Tensor对象 >>>A = tf ...

  2. 2、Redis如何配置成一个windows服务并且设置一键安装卸载与启停

    每天启动redis虽然只是一个命令行的事情,但是还是比较烦,所以…… 参考文档:Windows Service Documentation.docx 默认前提:Redis已安装并配置完成(不知道如何配 ...

  3. HTML中doctype的作用及几种类型详解

    一.DOCTYPE标签的定义与作用 <!DOCTYPE>是一个用于声明当前HTMl版本,用来告知web浏览器该文档使用是哪种 HTML 或者 XHTML 规范来解析页面,以便浏览器更加准确 ...

  4. 个人工作用SQL短句,不定时更新

    表字段操作 --一.修改字段默认值 alter table 表名 drop constraint 约束名字 ------说明:删除表的字段的原有约束 alter table 表名 add constr ...

  5. 2020年最佳Java调试工具(翻译)

    调试是应用程序开发周期不可或缺的一部分.用Java或任何其他语言编写程序时,每个开发人员应解决的首要问题之一是可靠的调试工具的可用性. 所使用的工具类型可能影响或破坏应用程序的调试过程,因此至关重要的 ...

  6. Jmeter系列(26)- 详解 JSON 提取器

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

  7. elasticSearch插件metricbeat收集nginx的度量指标

    ngx_http_stub_status_module模块是Nginx中用来统计Nginx服务所接收和处理的请求数量,只要在编译安装Nginx的时候加上参数--with-http_stub_statu ...

  8. android 6.0 权限设置详解

    从Android 6.0版本开始,在安装应用时,该应用无法取得任何权限. 相反,在使用应用的过程中,若某个功能需要获取某个权限,系统会弹出一个对话框,显式地由用户决定是否将该权限赋予应用. 只有得到了 ...

  9. android 中使用自定义权限

    1.如果在一个进程中启动另外一个进程的activity <?xml version="1.0" encoding="utf-8"?> <man ...

  10. 四层发现-UDP发现

    udp发现要注意选择一个不常用的端口,如果目标ip在up时目标端口是开放状态,那么不管目标ip是否为up状态,都不会收到任何回应,只有在目标ip为down状态且目标端口为关闭状态,才会返回一个目标不可 ...