我试图在Seismic Bumps数据集上运行一个kNN分类器,但当我试图为shift属性编码标签时,我得到了错误的值。这是代码:
col_names = ['seismic', 'seismoacoustic', 'shift',
'genergy', 'gpuls', 'gdenergy', 'gdpuls',
'ghazard', 'nbumps', 'nbumps2', 'nbumps3',
'nbumps4', 'nbumps5', 'nbumps6', 'nbumps7',
'nbumps89', 'energy', 'maxenergy', 'class']
# Import
sbumps_ds = pd.read_csv('SeismicBumpsDataset.csv', names = col_names)
from sklearn.preprocessing import LabelEncoder
labelenc = LabelEncoder()
# Encode class names to numbers
#sbumps_ds['seismic'] = labelenc.fit_transform(sbumps_ds.seismic)
#sbumps_ds['seismoacoustic'] = labelenc.fit_transform(sbumps_ds.seismoacoustic)
sbumps_ds['shift'] = labelenc.fit_transform(sbumps_ds.shift)
#sbumps_ds['ghazard'] = labelenc.fit_transform(sbumps_ds.ghazard)
#sbumps_ds['shift'] = sbumps_ds.shift.map({'W' : 0, 'N' : 1})
#sbumps_ds['seismic'] = sbumps_ds.seismic.map({'a':0, 'b':1, 'c':2, 'd': 3})
所有属性的形状都是相等的。错误如下:
raise ValueError("bad input shape {0}".format(shape))
ValueError: bad input shape ()
此外,当我尝试映射属性值时,我会得到以下错误:
sbumps_ds['shift'] = sbumps_ds.shift.map({'W' : 0, 'N' : 1})
AttributeError: 'function' object has no attribute 'map'
对于该属性,仅会引发错误。如果我更改了shift的名称,分类器就会工作。
尝试将其更改为sbumps_ds['shift'].map(...)
。
sbumpt_ds.shift
是一种数据帧方法,因此它返回该函数,而不是名为"shift"
的列。