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. c++构造函数的调用方法

    #include<iostream> using namespace std; class Base { public: Base(){ cout<<"hello&q ...

  2. 安装mysql报错:遇到缺少vcruntime140_1.dll文件

    把vcruntime140_1.dll文件放到System32 ,和System64就行 文件地址为:C:\Windows\System32 直接百度下载放进去就行

  3. jni 字符串的梳理 2 字符串的处理操作

    我们实现下面的一个功能: 1.首先在java层传递一个字符串到c层,c层首先将jstring转换成char*类型,然后将两个字符串相加,然后再再将char*类型转换成jstring,在上层显示出来 我 ...

  4. DataFrame索引和切片

    import numpy as np import pandas as pd from pandas import DataFrame, Seriesdf = DataFrame(data=np.ra ...

  5. 用一杯茶时间搭建Gitea服务器

     一.简单介绍 Gitea搭建局域网内的基于git的代码托管服务器,可以实现的功能包括:组织管理.团队管理.组织仓库设定.团队仓库分配.组织及团队权限分配管理.仓库添加PC协作者.仓库添加组织团队.分 ...

  6. vue全家桶(4.2)

    5.2.使用vuex重构上面代码 Vuex是什么?官方定义:Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式.它采用集中式存储管理应用的所有组件的状态,并以相应的规则保证状态以一种可预测 ...

  7. nginx使用热部署添加新模块

    简介 当初次编译安装nginx时,http_ssl_module 模块默认是不编译进nginx的二进制文件当中,如果需要添加 ssl 证书.也就是使用 https协议.那么则需要添加 http_ssl ...

  8. Python进阶之浅谈内置方法

    目录 有序or无序和可变or不可变 数字类型内置方法 整形 浮点型 字符串类型内置方法 有序or无序和可变or不可变 有序:有索引 无序:无索引 可变:变量值变,id不变 不可变:变量值变,id也变 ...

  9. Spring 容器的初始化

    读完这篇文章你将会收获到 了解到 Spring 容器初始化流程 ThreadLocal 在 Spring 中的最佳实践 面试中回答 Spring 容器初始化流程 引言 我们先从一个简单常见的代码入手分 ...

  10. mysql根据一张表更新另一张表数据

    UPDATE channelcountry, appywproducts SET channelcountry.ChannelName = appywproducts.YWNameCN WHERE c ...