【发布时间】:2019-07-01 09:50:00
【问题描述】:
如何查看在 TensorFlow 模型中训练的最终特征的价值。就像在下面的情况下,我试图对我的列“x”进行多重加热,我想看看这些功能是如何进入我的模型的。
这在 sklearn 中很容易做到,但对于 Tensorflow 来说是新手,我不明白这怎么可能。
import tensorflow as tf
import pandas as pd
data = {'x':['a c', 'a b', 'b c'], 'y': [1, 1, 0]}
df = pd.DataFrame(data)
Y = df['y']
X = df.drop('y', axis=1)
indicator_features = [tf.feature_column.indicator_column(categorical_column=
tf.feature_column.categorical_column_with_vocabulary_list(key = 'x',
vocabulary_list = ['a','b','c']))]
model = tf.estimator.LinearClassifier(feature_columns=indicator_features,
model_dir = "/tmp/samplemodel")
training_input_fn = tf.estimator.inputs.pandas_input_fn(x = X,
y=Y,
batch_size=64,
shuffle= True,
num_epochs = None)
model.train(input_fn=training_input_fn,steps=1000)
【问题讨论】:
-
你能在 sklearn 中发布你将如何做,以便我可以尝试复制它吗?
-
你试过 tf.Print() 吗?
-
@Sharky...我不明白如何在这里使用 tf.Print().. 有什么想法吗?
-
@gorjan.. 我可以简单地做类似这个例子的事情......chrisalbon.com/machine_learning/preprocessing_structured_data/…
-
@KundanKumar,您可以将任何张量传递给它。我不确定它是否可以与 tf.estimator.inputs.pandas_input_fn 一起使用,但是您可以尝试像 tf.Print(x, [x]) 一样将“x”传递给它
标签: tensorflow machine-learning data-science tensorboard