【问题标题】:Prediction using wide and deep learning network in TensorFlow在 TensorFlow 中使用广泛和深度学习网络进行预测
【发布时间】:2017-04-21 20:14:13
【问题描述】:

我已经在我的数据集上训练了一个广泛而深入的学习网络,其中包含属性 - product_id、views、likes、dislikes、shares、user_ratings。 user_ratings 被视为目标变量。我能够根据我提供的测试集评估我的模型。但我无法理解如何生成预测。我使用“预测”方法如下,但我得到的只是 [1]:

model.predict(input_fn=lambda : input_fn(df_train[:1]),as_iterable=False)

input_fn 在哪里:

def input_fn(df):
  continuous_cols = {k: tf.constant(df[k].values) for k in CONTINUOUS_COLUMNS}
  categorical_cols = {
  k: tf.SparseTensor(
      indices=[[i, 0] for i in range(df[k].size)],
      values=df[k].values,
      dense_shape=[df[k].size, 1])
  for k in CATEGORICAL_COLUMNS}
  feature_cols = dict(continuous_cols)
  feature_cols.update(categorical_cols)
  product_name = tf.constant(df[TARGET_COLUMN].values)
  return feature_cols, product_name

另外,在 df_train[:1] 中,我给出了 user_rating 值。但是当我尝试删除此列并执行它时,它显示一个错误。问题是模型正在处理二进制分类问题,但我想使用 10 个类别来进行用户评分(1 到 10)。

我怎样才能做到这一点?提前致谢。

【问题讨论】:

    标签: python tensorflow


    【解决方案1】:

    我通过将 -> n_classes=10 参数传递给模型解决了我的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-15
      • 2018-11-03
      • 2018-09-16
      • 1970-01-01
      • 2018-09-25
      相关资源
      最近更新 更多