如何将一个数组作为其值导入稀疏张量的数据帧?

2024-04-20 08:52:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个pandas dataframe,它包含一个字符串数组,我正试图将其导入到稀疏张量中,但是不管我怎么做,最终都会出现一个ValueError: too many values to unpack错误。在

数据帧

                                                  tags  
0    [cup, lighting, porcelain, saucer, cafeteria, ...  
2    [carrot, root, vegetable, produce, cucumber, f...

编码

在不共享所有代码的情况下,我使用DNNLinearCombinedClassifier并将标记导入定义为:

^{pr2}$

估计器是这样构建的(其中df是我的pandas数据帧):

statuses = df.pop('status')

tf.estimator.inputs.pandas_input_fn(
  x=df,
  y=statuses,
  batch_size=100,
  num_epochs=1,
  shuffle=False,
  num_threads=5,
  target_column='status')

当我调用估计器上的fit()时,我的代码就会失败。在

堆栈跟踪

Traceback (most recent call last):
  File "test.py", line 84, in <module>
    estimator.fit(input_fn=input_fn(df_train, num_epochs=None, shuffle=True), steps=500)
  File "/Users/user/tensorflow/lib/python2.7/site-packages/tensorflow/python/util/deprecation.py", line 289, in new_func
    return func(*args, **kwargs)
  File "/Users/user/tensorflow/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 455, in fit
    loss = self._train_model(input_fn=input_fn, hooks=hooks)
  File "/Users/user/tensorflow/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 953, in _train_model
    features, labels = input_fn()
ValueError: too many values to unpack

Tags: inpypandasdfinputtensorflowlinetrain