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)
可以使用,本人亲测
即可将其转为二维数组
python 使用sk_learn 遇到 问题ValueError: Expected 2D array, got 1D array instead:的更多相关文章
- 决策树python建模中的坑 :ValueError: Expected 2D array, got 1D array instead:
决策树python建模中的坑 代码 #coding=utf-8 from sklearn.feature_extraction import DictVectorizerimport csvfrom ...
- sklearn中报错ValueError: Expected 2D array, got 1D array instead:
from sklearn.linear_model import LinearRegression lr = LinearRegression() print(tr_x.shape,tr_y.shap ...
- [已解决]报错: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 ...
- 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 ...
- odoo开发笔记--ValueError Expected singleton
异常处理参考:https://stackoverflow.com/questions/31070640/valueerror-expected-singleton-odoo8 报错: ValueErr ...
- 解决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 ...
- 【Python】【内置函数】【bytes&bytearray&str&array】
[bytes] 英文文档: class bytes([source[, encoding[, errors]]]) Return a new “bytes” object, which is an i ...
- 笨方法学python中执行argv提示ValueError: not enough values to unpack (expected 4, got 1)
解决方法:选择Terminal中输入执行ex13.py 1 2 3 执行结果如下图
- 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 ...
随机推荐
- launch 文件解析
roslaunch工具是ros中python实现的程序启动工具,通过读取launch文件中的参数配置.属性配置等来启动一系列节点: 很多ROS包或源码包中都有launch文件,一般为该程序包能够运行起 ...
- .NET计时器的使用-Stopwatch类
作用: 微软提供的常用于统计时间消耗的类,作为一个固定的API接口供大家使用. 先看代码: using System; using System.Collections.Generic; using ...
- 面试:做过sql优化吗?
近来面试找工作经常会遇见这种问题: 做过数据库优化吗?大数据量基础过吗?系统反应慢怎么查询? 这咱也没背过啊,面试还老问,现在的网站主要的压力都来自于数据库,频繁的数据库访问经常会使系统瘫痪,这样就需 ...
- 20145219 《Java程序设计》第16周课程总结
20145219 <Java程序设计>第16周课程总结 每周读书笔记(即学习总结)链接汇总 第0周问卷调查 第1周读书笔记 第2周读书笔记 第3周读书笔记 第4周读书笔记 第5周读书笔记 ...
- Python 之 matplotlib (十六)Animation动画【转】
本文转载自:https://blog.csdn.net/wangsiji_buaa/article/details/80057875 代码: import matplotlib.pyplot as ...
- [Bzoj]5343: [Ctsc2018]混合果汁
5343: [Ctsc2018]混合果汁 题目描述 小 R 热衷于做黑暗料理,尤其是混合果汁. 商店里有 \(n\) 种果汁,编号为 \(0,1,\cdots,n-1\) .\(i\) 号果汁的美味度 ...
- 简单的aop实现日志打印(切入点表达式)
Spring中可以使用注解或XML文件配置的方式实现AOP. 1.导入jar包 com.springsource.net.sf.cglib -2.2.0.jar com.springsource.or ...
- tomcat绿色版——运行一闪而过的解决方法
首先配置好jdk的环境变量 %JAVA_HOME%\bin;注意:一定是英文状态下的分号结尾 %TOMCAT%\bin;注意:一定是英文状态下的分号结尾 service.bat install ser ...
- windows开dump
右键计算机—>属性—>高级系统设置——>设置——点击高级—>更改——>自定义大小(1024~2048)——设置保存
- centOS7.4 thinkPHP nginx 支持pathinfo和rewrite
server { listen 80; server_name www.demo.com mayifanx.com; root /data/www/demo; index index.php inde ...