这里我找到我的问题是:

使用的是一个新的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) 即可

python 使用sk_learn 遇到 问题ValueError: Expected 2D array, got 1D array instead:的更多相关文章

  1. 决策树python建模中的坑 :ValueError: Expected 2D array, got 1D array instead:

    决策树python建模中的坑 代码 #coding=utf-8 from sklearn.feature_extraction import DictVectorizerimport csvfrom ...

  2. sklearn中报错ValueError: Expected 2D array, got 1D array instead:

    from sklearn.linear_model import LinearRegression lr = LinearRegression() print(tr_x.shape,tr_y.shap ...

  3. [已解决]报错:ValueError: Expected 2D array, got scalar array instead

    报错代码: new_x = 84610 pre_y = model.predict(new_x) print(pre_y) 报错结果: ValueError: Expected 2D array, g ...

  4. pytorch报错:ValueError: Expected more than 1 value per channel when training, got input size torch.Size([1,512,1,1])

    1.pytorch报错:ValueError: Expected more than 1 value per channel when training, got input size torch.S ...

  5. odoo开发笔记--ValueError Expected singleton

    异常处理参考:https://stackoverflow.com/questions/31070640/valueerror-expected-singleton-odoo8 报错: ValueErr ...

  6. 解决Tensorflow ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray)

    问题描述 在将一个数组送入tensorflow训练时,报错如下: ValueError: Failed to convert a NumPy array to a Tensor (Unsupporte ...

  7. 【Python】【内置函数】【bytes&bytearray&str&array】

    [bytes] 英文文档: class bytes([source[, encoding[, errors]]]) Return a new “bytes” object, which is an i ...

  8. 笨方法学python中执行argv提示ValueError: not enough values to unpack (expected 4, got 1)

    解决方法:选择Terminal中输入执行ex13.py 1 2 3 执行结果如下图

  9. python写入文本报错TypeError: expected a string or other character buffer object

    今天用python写入文本, file_object2 = open('result.txt', 'w') file_object2.write(bookid_list) file_object2.c ...

随机推荐

  1. 字符数组(char)和字符串(string)的转换

    #include<iostream>#include<string>using namespace std;void main(){ string LyuS = "W ...

  2. 手机调取摄像头问题(getUserMedia)

    先说坏消息,苹果机没法玩这个!!! 而且,必须拥有 https 的安全协议!!! 而安卓机想完成这个功能倒是很 easy 的,看一眼代码 主要传入三个参数,配置对象,成功,失败 var mediaOp ...

  3. c刷新缓冲区

    int c; while((c = getchar()) != '\n' && c != EOF);

  4. lamp架构之升级php版本

    当你看到这篇文章的时候 YHSPY.COM 服务器上的PHP版本已经从 5.4.27 升级到了 7.0.4,这是一个重大的飞跃.一路升级遇到了很多问题.官方声称PHP7最大的升级就是在语言性能上的提升 ...

  5. JavaEE初始化时静态代码块加载问题

    1.使用java.exe命令运行某个类的时java.exe Person2.创建一个类的对象时Person p=new Person();3.访问类中的静态成员变量(赋值/获取值)System.out ...

  6. java中HashMap集合的常用方法

    public Object clone() 返回hashMap集合的副本 其余的方法都是实现Map集合的 https://www.cnblogs.com/xiaostudy/p/9510763.htm ...

  7. Spring -- 如何为applicationContext.xml 添加 util 的 *.xsd文件

  8. SqlServer、oracle、mysql分页的实现

    我们在编写MIS系统和Web应用程序等系统时,都涉及到与数据库的交互,如果数据库中数据量很大的话,一次检索所有的记录,会占用系统很大的资源,因此我们常常采用,需要多少数据就只从数据库中取多少条记录,即 ...

  9. 资源(GitHub)

    angular 文档 https://angular.cn/docs/ts/latest/quickstart.html   http://sc.qq.com/fx/u?r=OfFE5AA ios h ...

  10. angular-schema-form 自动表单生成

    基本用法 通过bower安装之后,将schemaForm模块载入到模块定义中,fuse中安装第三方包需要在app/core/core.module.js中声明. 然后在controller里面,将sc ...