预测类的输出
array([ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 4, 4, 2, 4, 4, 4, 4, 5, 4, 4, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 7, 7, 7, 7, 7, 7, 7, 13, 7, 7, 8, 11, 8, 8, 8,
11, 8, 11, 11, 8, 11, 9, 9, 9, 9, 9, 9, 9, 9, 8, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 8, 11, 11, 11,
11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 3, 13, 3,
3, 13, 13, 13, 14, 14, 14, 14, 14, 14, 2, 14, 14, 14, 15, 15, 15,
15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 20, 16, 16,
17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 19, 19, 19, 19, 8, 19, 19, 19, 19, 19, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22,
22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25,
25, 25, 25, 25, 25])
y_的输出为真
0 0 1 0 2 0 3 0 4 0 .. 255 25 256 25 257 25 258 25 259 25 Name: label, Length: 260, dtype: int64
我想得到这个代码的索引,并得到这个值错误。
predicted_classes = model.predict_classes(X_test)
y_true = data_test.iloc[:, 0]
correct = np.nonzero(predicted_classes==y_true)[0]
incorrect = np.nonzero(predicted_classes!=y_true)[0]
错误痕迹
ValueError Traceback (most recent call last) in 4 #get the indices to be plotted 5 y_true = data_test.iloc[:, 0] ----> 6 correct = np.nonzero(predicted_classes!=y_true)[0] 7 incorrect = np.nonzero(predicted_classes==y_true)[0] in nonzero(*args, **kwargs) //anaconda3/lib/python3.7/site-packages/numpy/core/fromnumeric.py in nonzero(a) 1894 1895 """ -> 1896 return _wrapfunc(a, 'nonzero') 1897 1898 //anaconda3/lib/python3.7/site-packages/numpy/core/fromnumeric.py in _wrapfunc(obj, method, *args, **kwds) 56 bound = getattr(obj, method, None) 57 if bound is None: ---> 58 return _wrapit(obj, method, *args, **kwds) 59 60 try: //anaconda3/lib/python3.7/site-packages/numpy/core/fromnumeric.py in _wrapit(obj, method, *args, **kwds) 49 if not isinstance(result, mu.ndarray): 50 result = asarray(result) ---> 51 result = wrap(result) 52 return result 53 //anaconda3/lib/python3.7/site-packages/pandas/core/generic.py in __array_wrap__(self, result, context) 1916 return result 1917 d = self._construct_axes_dict(self._AXIS_ORDERS, copy=False) -> 1918 return self._constructor(result, **d).__finalize__(self) 1919 1920 # ideally we would define this to avoid the getattr checks, but //anaconda3/lib/python3.7/site-packages/pandas/core/series.py in __init__(self, data, index, dtype, name, copy, fastpath) 290 if len(index) != len(data): 291 raise ValueError( --> 292 f"Length of passed values is {len(data)}, " 293 f"index implies {len(index)}." 294 ) ValueError: Length of passed values is 1, index implies 260.
请告诉我哪里出了问题。
快速搜索发现,旧版本的文档建议使用.to_numpy().nonzero()
替换系列.nonzero()
。
我正在登录各种网络设备,并尝试查看输出。下面是我正在运行的脚本,它工作得非常好。当我试图确定po1、allin1、sta1、saa1、stn1的产量时,我面临着这个问题。我已经给出了下面所有变量的输出。po1将是这里的源,如果任何索引在其他变量中不可用,则需要显示“NAn”。如果你对理解这个问题有异议,请告诉我。 下面是我得到的错误。当我把轴设为1时,我得到了这个错误。 po1的产量: allin
问题内容: 我正在尝试获取新的数据集,或将当前数据集列的值更改为其唯一值。这是我尝试获得的示例: 我不太在乎索引,但这似乎是问题所在。到目前为止,我的代码非常简单,我尝试了两种方法,一种是使用新的dataFrame,另一种是不使用。 两次都出现错误“值的长度与索引的长度不匹配”。 问题答案: 当您尝试向数据帧分配不同长度的numpy数组列表时,会出现此错误,并且可以按以下方式重现该错误: 四行数据
我以前在python中使用pyodbc,但现在我已经在一台新机器上安装了它(win 8 64位、python 2.7 64位、PythonXY和Spyder)。 我不知道为什么行为会改变。也许是我的Pandas版本,或者是pyodbc,但是更新是有问题的。我试图更新一些模块,但它搞砸了一切,我使用的任何方法(二进制文件--用于正确的机器/安装--PIP安装、easy-install,任何东西!等等
问题内容: 我有一张这样的桌子: 和这样的一个: 和这样的SQL语句 如果我解释给我这个: 对于一百万行,这非常慢。我尝试使用以下方法在products.name上添加索引: 这给出了: 我认为Sub_part列显示已在索引中(以字节为单位)的前缀,如本页中所述。 当我重新解释查询时,我得到: 看起来好像没有使用新索引。如 本页所述,如果索引是前缀索引,则不会用于排序。实际上,如果我用以下方法截断
我在尝试读取csv文件时遇到问题,错误如下所示: 。我尝试过在堆栈溢出中搜索,错误与上面相同。 法典: MyCSVFile: