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. @loj - 2977@ 「THUSCH 2017」巧克力

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 「人生就像一盒巧克力,你永远不知道吃到的下一块是什么味道.」 明 ...

  2. windows server2012 安装SQL SERVER 2016环境监测出错

    Windows Server 2012 R2 安装SQL Server 2016 顺序为:KB2919442 ——> KB2919355 ——> SQL Server 2016 并且还要安 ...

  3. Tensorflow中Tensor对象的常用方法(持续更新)

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

  4. WINCC 应用与提高(78讲15.98G)视频教程网盘下载

    收集与网络,供参考. https://blog.csdn.net/txwtech/article/details/94225748

  5. Jenkins自动化测试脚本的构建

    [准备环境] 自动化测试框架脚本 Linux下的Python环境    https://www.cnblogs.com/xinhua19/p/12836522.html [思路] 测试顺序是,测试通过 ...

  6. IDEA自定义类注释和方法注释(自定义groovyScript方法实现多行参数注释)

    一.类注释 1.打开设置面板:file -> setting -> Editor -> file and code Templates 选择其中的inclues选项卡,并选择File ...

  7. Git在windows使用git时出现:warning: LF will be replaced by CRLF

    $ rm -rf .git  // 删除.git $ git config --global core.autocrlf false  //禁用自动转换 $ git init $ git add

  8. HashMap的基本使用

    常用方法 首先,我们应该知道HashMap类实现了Map接口,所以实现了Map常用的一些方法. (1) 插入键值对数据 public V put(K key, V value) (2)根据键值获取键值 ...

  9. Package Control:There are no packages available for installation

    百度推荐的sublime3,里面好多全家桶,注意安装. 我的问题报错是:Package Control:There are no packages available for installation ...

  10. sublime清空控制台

    解决方法 – 只需运行print('\n'*100)打印100个换行符,您将无法看到任何以前的输出,除非你向上滚动一些距离.