0
votes

Trying to execute the next code:

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)

I am getting the next error:

File "mlSVM.py", line 68, in classifier.fit(input_fn=input_fn, steps=2000)

File "/home/walker/tf/local/lib/python2.7/site-packages/tensorflow/python/util/deprecation.py", line 316, in new_func return func(*args, **kwargs)

File "/home/walker/tf/local/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 480, in fit loss = self._train_model(input_fn=input_fn, hooks=hooks)

File "/home/walker/tf/local/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 986, in _train_model model_fn_ops = self._get_train_ops(features, labels)

File "/home/walker/tf/local/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 1202, in _get_train_ops return self._call_model_fn(features, labels, model_fn_lib.ModeKeys.TRAIN)

File "/home/walker/tf/local/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 1166, in _call_model_fn model_fn_results = self._model_fn(features, labels, **kwargs)

File "/home/walker/tf/local/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/estimators/linear.py", line 244, in sdca_model_fn features.update(layers.transform_features(features, feature_columns))

File "/home/walker/tf/local/lib/python2.7/site-packages/tensorflow/contrib/layers/python/layers/feature_column_ops.py", line 647, in transform_features transformer.transform(column)

File "/home/walker/tf/local/lib/python2.7/site-packages/tensorflow/contrib/layers/python/layers/feature_column_ops.py", line 838, in transform feature_column.insert_transformed_feature(self._columns_to_tensors)

AttributeError: '_NumericColumn' object has no attribute 'insert_transformed_feature'

How could it be resolved?

1

1 Answers

2
votes

This is happening because you're mixing the SVM estimator from tf.contrib with the feature columns from core TensorFlow (tf.feature_column.numeric_column).

Try using the contrib version of the feature columns. Replace tf.feature_column.numeric_column(k) with tf.contrib.layers.real_valued_column(k).

This article gives some more context on why this is an issue.