KeyError训练值

时间:2019-11-12 00:21:55

标签: python arrays pandas numpy keyerror

运行下面的代码片段时,我收到一条错误消息,一切似乎对我未经培训的眼睛都是正确的。香港专业教育学院试图找出错误无济于事。

Training Model KeyError

# Specify arrays with input feature values
trainX = train[list(train)[1:]].values # numpy array with training inputs
testX = test[list(train)[1:]].values # numpy array with test inputs

# Specify arrays with output value labels
trainY = train.label.values #output labels for training examples
testY = test.label.values # output labels for test examples

# Show dimensions for arrays
print('Train on %d labeled observations with %d input features.' 
%trainX.shape)
print('Test on %d labeled observations with %d input features' 
%testX.shape)`

错误:

    KeyError                                  Traceback (most recent call 
last)
<ipython-input-66-0e3d6e12b557> in <module>()
 1 trainX = train[list(train)[1:]].values # numpy array with training 
inputs
----> 2 testX = test[list(train)[1:]].values # numpy array with test 
inputs
  3 
  4 # Specify arrays with output value labels
  5 trainY = train.label.values #output labels for training examples

1 个答案:

答案 0 :(得分:0)

输入文件和变量不正确