我如何得到评级预测?

时间:2017-10-18 06:26:22

标签: tensorflow predict tensorboard

我使用DNNClassifier Estimator,我想预测评级。

但是,我不知道使用预测。

我期待下面的结果。

预测评级:XX

PLZ,帮帮我,给我一个指南(使用预测)

下面,我的代码。

""" Define """
JOIN_CSV_COLUMNS         = ['USER_ID', 'CONTENT_ID', 'CONTENT_NAME_USER', 'RATING', 'CNTY_CD', 'FIRST_ORD_DD', 'LAST_ORD_DD', 'DVCE_MODEL_ID', 'DWN_CNT', 'RATING_AVG', 'CONTENT_NAME_CONTENT', 'PKG_ID', 'LANG', 'TAGS', 'CATEGORY_NAME',
                            'SLR_ID', 'SLR_CNTY_CD', 'DVCE_LIST', 'FIRST_SALE_DATE', 'RTG_AVG', 'CMT_CNT', 'DESC_LENGTH', 'PRIVILGE', 'REV_COUNT', 'REJ_COUNT', 'PRICE']

""" Numeric Column """
NF_CONTENT_ID       = tf.feature_column.numeric_column('CONTENT_ID')
NF_RATING           = tf.feature_column.numeric_column('RATING')
NF_FIRST_ORD_DD     = tf.feature_column.numeric_column('FIRST_ORD_DD')
NF_LAST_ORD_DD      = tf.feature_column.numeric_column('LAST_ORD_DD')


""" Categorical Column """
CF_USER_ID              = tf.feature_column.categorical_column_with_hash_bucket('USER_ID', hash_bucket_size=1000)
CF_CONTENT_NAME_USER    = tf.feature_column.categorical_column_with_hash_bucket('CONTENT_NAME_USER', hash_bucket_size=1000)
CF_CNTY_CD              = tf.feature_column.categorical_column_with_hash_bucket('CNTY_CD', hash_bucket_size=1000)

crossed_columns = [
    tf.feature_column.crossed_column(['RATING_AVG', 'RTG_AVG'], hash_bucket_size=1000),
    tf.feature_column.crossed_column(['RATING_AVG', 'PRICE'], hash_bucket_size=1000),
    tf.feature_column.crossed_column(['RATING_AVG', 'CNTY_CD'], hash_bucket_size=1000),
    tf.feature_column.crossed_column(['RATING_AVG', 'CATEGORY_NAME'], hash_bucket_size=1000),
    tf.feature_column.crossed_column(['RTG_AVG', 'TAGS'], hash_bucket_size=1000),
    tf.feature_column.crossed_column(['CONTENT_NAME_USER', 'TAGS'], hash_bucket_size=1000),
    tf.feature_column.crossed_column(['RATING_AVG', 'DWN_CNT'], hash_bucket_size=1000)
    ]

deep_columns = [
    tf.feature_column.indicator_column(CF_USER_ID),
    tf.feature_column.indicator_column(CF_CONTENT_NAME_USER),
    tf.feature_column.indicator_column(CF_CNTY_CD),
    tf.feature_column.indicator_column(CF_DVCE_MODEL_ID),
    tf.feature_column.indicator_column(CF_CONTENT_NAME_CONTENT),

    NF_CONTENT_ID,
    NF_FIRST_ORD_DD,
    NF_LAST_ORD_DD,
    NF_DWN_CNT,
    NF_RATING_AVG,
    ]

def get_input_fn(data_set, num_epochs=None, shuffle=True):
  return tf.estimator.inputs.pandas_input_fn(
      x=data_set,
      y=data_set["RATING"],
      num_epochs=num_epochs,
      shuffle=shuffle)


def main(unused_argv):
  # Load datasets
  training_set = pd.read_csv("./data/Test/train.csv", encoding ='ISO-8859-1', skipinitialspace=True, skiprows=1, names=JOIN_CSV_COLUMNS)
  test_set = pd.read_csv("./data/Test/test.csv", encoding ='ISO-8859-1',skipinitialspace=True, skiprows=1, names=JOIN_CSV_COLUMNS)

  # Set of 6 examples for which to predict median house values
  prediction_set = pd.read_csv("./data/Test/predict.csv", encoding ='ISO-8859-1',skipinitialspace=True, skiprows=1, names=JOIN_CSV_COLUMNS)

  # Build 2 layer fully connected DNN with 10, 10 units respectively.
  m = tf.estimator.DNNLinearCombinedClassifier(
      model_dir=None,
      linear_feature_columns=crossed_columns,
      dnn_feature_columns=deep_columns,
      dnn_hidden_units=[1, 1],
      dnn_optimizer='Adam',
      dnn_dropout=0.5,
      n_classes=6
  )

  # Train
  m.train(input_fn=get_input_fn(training_set), steps=1000)

  # Evaluate loss over one epoch of test_set.
  ev = m.evaluate(input_fn=get_input_fn(test_set, num_epochs=1, shuffle=False))

if __name__ == "__main__":
  tf.app.run()

1 个答案:

答案 0 :(得分:0)

您可以使用以下部分进行预测。

if