zoukankan      html  css  js  c++  java
  • 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) 即可


  • 相关阅读:
    Eclipse Mac OS 安装 Subversion插件subclipse 缺失JavaHL解决方案
    Eclipse Mac OS 安装 最新版 Subversion插件subclipse
    mac OS 安装 Homebrew软件包管理器
    Ribbon 框架简介及搭建
    Ribbon 框架简介及搭建
    TinyMCE下载及使用
    努力啊。
    逃离
    怎么学习
    烂代码
  • 原文地址:https://www.cnblogs.com/blogwangwang/p/9608152.html
Copyright © 2011-2022 走看看