KeyError: 0 when using preprocess_test

KeyError: 0 when using preprocess_test

preprocess_train运行成功。

有没有人在使用preprocess_test/ktrain(0.18.5)时遇到过类似的KeyError?

preprocessing test...
language: en
test sequence lengths:
    mean : 608
    95percentile : 2102
    99percentile : 4783
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
 in 
----> 1 val = t.preprocess_test(X_test, y_test)

~/.local/lib/python3.6/site-packages/ktrain/text/preprocessor.py in preprocess_test(self, texts, y, verbose)
   1172         """
   1173         self.check_trained()
-> 1174         return self.preprocess_train(texts, y=y, mode='test', verbose=verbose)
   1175 
   1176 

~/.local/lib/python3.6/site-packages/ktrain/text/preprocessor.py in preprocess_train(self, texts, y, mode, verbose)
   1142           TransformerDataset if self.use_with_learner = True else tf.Dataset
   1143         """
-> 1144         tseq = super().preprocess_train(texts, y=y, mode=mode, verbose=verbose)
   1145         if self.use_with_learner: return tseq
   1146         tseq.batch_size = self.batch_size

~/.local/lib/python3.6/site-packages/ktrain/text/preprocessor.py in preprocess_train(self, texts, y, mode, verbose)
    910         elif y is None:
    911             y = np.array([1] * len(texts))
--> 912         y = self._transform_y(y, verbose=verbose)
    913 
    914         # convert examples

~/.local/lib/python3.6/site-packages/ktrain/text/preprocessor.py in _transform_y(self, y_data, verbose)
    505 
    506         # check for errors and warnings
--> 507         if not isinstance(y_data[0], str) and len(y_data.shape) ==1 and not self.get_classes():
    508             if verbose:
    509                 warnings.warn('Task is being treated as TEXT REGRESSION because ' +\

~/.local/lib/python3.6/site-packages/pandas/core/series.py in __getitem__(self, key)
    869         key = com.apply_if_callable(key, self)
    870         try:
--> 871             result = self.index.get_value(self, key)
    872 
    873             if not is_scalar(result):

~/.local/lib/python3.6/site-packages/pandas/core/indexes/base.py in get_value(self, series, key)
   4403         k = self._convert_scalar_indexer(k, kind="getitem")
   4404         try:
-> 4405             return self._engine.get_value(s, k, tz=getattr(series.dtype, "tz", None))
   4406         except KeyError as e1:
   4407             if len(self) > 0 and (self.holds_integer() or self.is_boolean()):

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_value()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_value()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()

KeyError: 0

您似乎在向 preprocess_test 提供 pandas 系列,而不是 NumPy 数组或 Python 列表。如果X_testy_test是pandas系列,则将X_test.valuesy_test.values提供给preprocess_test