\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in __getitem__(self, key)

\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in __getitem__(self, key)
   1752 
   1753         key = _values_from_object(key)
-> 1754         result = getitem(key)
   1755         if not is_scalar(result):
   1756             return promote(result)

boolean index did not match indexed array along dimension 0; dimension is 4 but corresponding boolean dimension is 3

 

在学习回归算法的时候,使用sklearn.linear_model下的RandomizedLogisticRegression里面有个get_support()方法,筛选数据中的特征量时候,容易出现以下错误,例如:“布尔索引不匹配维数为0的索引数组;维数为4,对应的布尔维数为3”维数不匹配错误,通过网上找相关问题的解决办法,问题是在get_support的参数中,需要将参数设置为get_support(indices=True)就好了。

可以看到returns部分,大概意思就是Indices是False,就返回一个类型是boolean的数组,如果indices是True,就返回一个整型数组,所以解决办法就是把参数改变。默认的是False,解决办法就是把它变成Ture。

 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
TypeError Traceback (most recent call last) D:\Anaconda\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance) 3628 try: -> 3629 return self._engine.get_loc(casted_key) 3630 except KeyError as err: D:\Anaconda\lib\site-packages\pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc() D:\Anaconda\lib\site-packages\pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc() TypeError: '(slice(None, None, None), 0)' is an invalid key During handling of the above exception, another exception occurred: InvalidIndexError Traceback (most recent call last) ~\AppData\Local\Temp\ipykernel_5316\790738290.py in <module> ----> 1 target=wine_data[:,0] 2 data=wine_data[:,1:] D:\Anaconda\lib\site-packages\pandas\core\frame.py in __getitem__(self, key) 3503 if self.columns.nlevels > 1: 3504 return self._getitem_multilevel(key) -> 3505 indexer = self.columns.get_loc(key) 3506 if is_integer(indexer): 3507 indexer = [indexer] D:\Anaconda\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance) 3634 # InvalidIndexError. Otherwise we fall through and re-raise 3635 # the TypeError. -> 3636 self._check_indexing_error(key) 3637 raise 3638 D:\Anaconda\lib\site-packages\pandas\core\indexes\base.py in _check_indexing_error(self, key) 5649 # if key is not a scalar, directly raise an error (the code below 5650 # would convert to numpy arrays and raise later any way) - GH29926 -> 5651 raise InvalidIndexError(key) 5652 5653 @cache_readonly InvalidIndexError: (slice(None, None, None), 0)
05-31
Traceback (most recent call last): File "D:\Anaconda\lib\site-packages\pandas\core\indexes\base.py", line 3802, in get_loc return self._engine.get_loc(casted_key) File "pandas\_libs\index.pyx", line 138, in pandas._libs.index.IndexEngine.get_loc File "pandas\_libs\index.pyx", line 165, in pandas._libs.index.IndexEngine.get_loc File "pandas\_libs\hashtable_class_helper.pxi", line 5745, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas\_libs\hashtable_class_helper.pxi", line 5753, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'A' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "e:\Mydata\py\提取指定范围excel数据.py", line 7, in <module> data = df.loc[0:9, 'A':'B'] # 例如提取第1行到第10行,第1列到第3列的数据 File "D:\Anaconda\lib\site-packages\pandas\core\indexing.py", line 1067, in __getitem__ return self._getitem_tuple(key) File "D:\Anaconda\lib\site-packages\pandas\core\indexing.py", line 1256, in _getitem_tuple return self._getitem_tuple_same_dim(tup) File "D:\Anaconda\lib\site-packages\pandas\core\indexing.py", line 924, in _getitem_tuple_same_dim retval = getattr(retval, self.name)._getitem_axis(key, axis=i) File "D:\Anaconda\lib\site-packages\pandas\core\indexing.py", line 1290, in _getitem_axis return self._get_slice_axis(key, axis=axis) File "D:\Anaconda\lib\site-packages\pandas\core\indexing.py", line 1324, in _get_slice_axis indexer = labels.slice_indexer(slice_obj.start, slice_obj.stop, slice_obj.step) File "D:\Anaconda\lib\site-packages\pandas\core\indexes\base.py", line 6559, in slice_indexer start_slice, end_slice = self.slice_locs(start, end, step=step) File "D:\Anaconda\lib\site-packages\pandas\core\indexes\base.py", line 6767, in slice_locs start_slice = self.get_slice_bound(start, "left") File "D:\Anaconda\lib\site-packages\pandas\core\indexes\base.py", line 6686, in get_slice_bound raise err File "D:\Anaconda\lib\site-packages\pandas\core\indexes\base.py", line 6680, in get_slice_bound slc = self.get_loc(label) File "D:\Anaconda\lib\site-packages\pandas\core\indexes\base.py", line 3804, in get_loc raise KeyError(key) from err KeyError: 'A'
最新发布
07-16
Traceback (most recent call last): File "D:\anaconda\envs\mytest\lib\site-packages\pandas\core\indexes\base.py", line 3081, in get_loc return self._engine.get_loc(casted_key) File "pandas\_libs\index.pyx", line 70, in pandas._libs.index.IndexEngine.get_loc File "pandas\_libs\index.pyx", line 101, in pandas._libs.index.IndexEngine.get_loc File "pandas\_libs\hashtable_class_helper.pxi", line 1625, in pandas._libs.hashtable.Int64HashTable.get_item File "pandas\_libs\hashtable_class_helper.pxi", line 1632, in pandas._libs.hashtable.Int64HashTable.get_item KeyError: 0 The above exception was the direct cause of the following exception: Traceback (most recent call last): File "D:\PyCharm\learning\1\BPmain.py", line 28, in <module> if test_output.loc[i, 0] == y_pred[i, 0]: File "D:\anaconda\envs\mytest\lib\site-packages\pandas\core\indexing.py", line 889, in __getitem__ return self._getitem_tuple(key) File "D:\anaconda\envs\mytest\lib\site-packages\pandas\core\indexing.py", line 1060, in _getitem_tuple return self._getitem_lowerdim(tup) File "D:\anaconda\envs\mytest\lib\site-packages\pandas\core\indexing.py", line 831, in _getitem_lowerdim return getattr(section, self.name)[new_key] File "D:\anaconda\envs\mytest\lib\site-packages\pandas\core\indexing.py", line 895, in __getitem__ return self._getitem_axis(maybe_callable, axis=axis) File "D:\anaconda\envs\mytest\lib\site-packages\pandas\core\indexing.py", line 1124, in _getitem_axis return self._get_label(key, axis=axis) File "D:\anaconda\envs\mytest\lib\site-packages\pandas\core\indexing.py", line 1073, in _get_label return self.obj.xs(label, axis=axis) File "D:\anaconda\envs\mytest\lib\site-packages\pandas\core\generic.py", line 3739, in xs loc = index.get_loc(key) File "D:\anaconda\envs\mytest\lib\site-packages\pandas\core\indexes\base.py", line 3083, in get_loc raise KeyError(key) from err KeyError: 0
07-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值