• python 使用sk_learn 遇到 问题ValueError: Expected 2D array, got 1D array instead:


    这里我找到我的问题是:



    使用的是一个新的scikit学习版本,它抛出了一个错误,因为在新版本中,所有东西都必须是一个二维矩阵,甚至是一个列或行。

    它甚至说:用数组来重塑你的数据。如果您的数据有一个单独的特性或数组,那么重构(-1,1)。重构(1,-1)如果它包含一个单一的样本


    这是在git上面看到的一个国际友人的解答。

    原文,如下:

    I think you're using a new scikit-learn version and it's throwing an error because in the new version everything has to be a 2d matrix, even a single column or row.


    It even says: Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.


    Have you tried this on your y column?

    我遇到的就是这个问题,因为我使用的sklearn 是anaconda的3.5版本,应该是最新版本,所以出现了这个问题吧

    然后我们来看看解决问题的方法:

    调用 xx.reshape(1,-1)

    可以使用,本人亲测

    即可将其转为二维数组

    各位加油!

    有人问起怎么调用了,这里我说下  ,直接用需要修改的 数组名.reshape(1,-1) 即可


  • 相关阅读:
    PHP的反射机制
    mysqlbinlog
    PHP调用java的class
    ecshop session机制
    memory_limit session.cache_expire ecshop初始化注释说明
    ecshop运行超过30秒超时的限制解决办法
    如果你想拥有事业,而非仅仅是工作
    扎克伯格谈”人际交往”趋势
    Magento架构分析,Magento MVC 设计分析
    推荐的PHP编码规范
  • 原文地址:https://www.cnblogs.com/blogwangwang/p/9608152.html
Copyright © 2020-2023  润新知