使用:
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行,in classifier.fit(input_fn = input_fn,steps = 2000) 在new_func中输入文件“/home/walker/tf/local/lib/python2.7/site-packages/tensorflow/python/util/deprecation.py”,第316行 return func(* args,** kwargs) 文件“/home/walker/tf/local/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py”,第480行,in fit loss = self._train_model(input_fn = input_fn,hooks = hooks) 在_train_model中输入文件“/home/walker/tf/local/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py”,第986行 model_fn_ops = self._get_train_ops(功能,标签) 在_get_train_ops中输入文件“/home/walker/tf/local/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py”,第1202行 return self._call_model_fn(features,labels,model_fn_lib.ModeKeys.TRAIN) 在_call_model_fn中输入文件“/home/walker/tf/local/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py”,第1166行 model_fn_results = self._model_fn(features,labels,** kwargs) 在sdca_model_fn中输入文件“/home/walker/tf/local/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/estimators/linear.py”,第244行 features.update(layers.transform_features(features,feature_columns)) 在transform_features中输入文件“/home/walker/tf/local/lib/python2.7/site-packages/tensorflow/contrib/layers/python/layers/feature_column_ops.py”,第647行 transformer.transform(列) 文件“/home/walker/tf/local/lib/python2.7/site-packages/tensorflow/contrib/layers/python/layers/feature_column_ops.py”,第838行,在变换中 feature_column.insert_transformed_feature(self._columns_to_tensors) AttributeError:'_ NomericColumn'对象没有属性'insert_transformed_feature'
答案 0 :(得分:2)
这种情况正在发生,因为您正在将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提供了更多关于这是一个问题的背景信息。