tf.estimator.inputs.pandas_input_fn抛出_NumericColumn ' object has no attribute ' insert_transformed_feature

附:

feature_cols = [tf.feature_column.numeric_column(k) for k in df.columns.values]

classifier = tf.contrib.learn.SVM( example_id_column='example_id', feature_columns=feature_cols, l2_regularization=10.0)

input_fn = tf.estimator.inputs.pandas_input_fn(
    x=pd.DataFrame(df),
    y=pd.Series(score),
batch_size=128,
    num_epochs=1,
    shuffle=False,
    queue_capacity=1000,
    num_threads=1,
    target_column='target'
    )

classifier.fit(input_fn=input_fn, steps=2000)

我收到错误:

分类器中的文件“mlSVM.py”,第68行(input_fn = input_fn,steps = 2000)文件“/home/walker/tf/local/lib/python2.7/site-packages/tensorflow/python/util/ deprecation.py“,第316行,在new_func中返回func(* args,** kwargs)文件”/home/walker/tf/local/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn /estimators/estimator.py“,第480行,适合损失= self._train_model(input_fn = input_fn,hooks = hooks)文件”/home/walker/tf/local/lib/python2.7/site-packages/tensorflow/ contrib / learn / python / learn / estimators / estimator.py“,第986行,_train_model model_fn_ops = self._get_train_ops(features,labels)文件”/home/walker/tf/local/lib/python2.7/site-packages /tensorflow/contrib/learn/python/learn/estimators/estimator.py“,第1202行,在_get_train_ops中返回self._call_model_fn(features,labels,model_fn_lib.ModeKeys.TRAIN)文件”/ home / walker / tf / local / lib /python2.7/site-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py“,第1166行,在_call_model_fn model_fn_resu lts = self._model_fn(features,labels,** kwargs)File“/home/walker/tf/local/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/estimators/linear.py “,第244行,在sdca_model_fn features.update(layers.transform_features(features,feature_columns))文件”/home/walker/tf/local/lib/python2.7/site-packages/tensorflow/contrib/layers/python/layers /feature_column_ops.py“,第647行,在transform_features transformer.transform(column)文件中”/home/walker/tf/local/lib/python2.7/site-packages/tensorflow/contrib/layers/python/layers/feature_column_ops . py“,第838行,在transform feature_column.insert_transformed_feature(self.columns_to_tensors)中AttributeError:' NomericColumn'对象没有属性'insert_transformed_feature'

回答(1)

2 years ago

之所以发生这种情况,是因为您将来自 tf.contrib 的SVM估算器与来自核心TensorFlow( tf.feature_column.numeric_column )的要素列混合在一起 .

尝试使用功能列的contrib版本 . 将 tf.feature_column.numeric_column(k) 替换为 tf.contrib.layers.real_valued_column(k) .

This article提供了更多关于为什么这是一个问题的背景信息 .