TensorFlow培训不起作用:模型不是学习数据

时间:2017-08-30 19:12:22

标签: machine-learning tensorflow neural-network deep-learning regression

我有一个超过1700万观测数据集,我正在尝试使用它来训练 Build command failed. Error while executing process /Users/xingyugu/Library/Android/sdk/cmake/3.6.4111459/bin/cmake with arguments {--build /Users/xingyugu/Desktop/Hello_jni/app/.externalNativeBuild/cmake/debug/mips64 --target native-lib} ninja: error: 'src/main/jniLabs/armeabi-v7a/mips64/libkface.so', needed by '../../../../build/intermediates/cmake/debug/obj/mips64/libnative-lib.so', missing and no known rule to make it 模型。但是,培训根本不起作用。损失大约为10 ^ 15,这简直令人恐怖。几个星期以来,我一直在尝试不同的事情,无论我做什么,我都无法承受失败。

例如,在训练之后,我使用用于训练数据的相同观察之一进行测试。预期结果为DNNRegressor,但预测结果140944.00,这是荒谬的。训练数据中甚至没有任何负值,我也不明白它是如何消失的。

以下是一些示例培训数据:

-169532.5

这是我的代码:

Amount      Contribution    ServiceType     Percentile       Time   Result
214871.00   3501.00         SM23            high             50     17807828.00
214871.00   3501.00         SM23            high             51     19216520.00
214871.00   3501.00         SM23            high             52     19676064.00
214871.00   3501.00         SM23            high             53     21038840.00
214871.00   3501.00         SM23            high             54     22248295.00
214871.00   3501.00         SM23            high             55     22412713.00
28006.00    83.00           SM0             i_low            0      28006.00
28006.00    83.00           SM0             i_low            1      28804.00
28006.00    83.00           SM0             i_low            2      30140.00
28006.00    83.00           SM0             i_low            3      31598.00
28006.00    83.00           SM0             i_low            4      33130.00
28006.00    83.00           SM0             i_low            5      34663.00

feature_columns = [ tf.feature_column.numeric_column('Amount', dtype=dtypes.float32), tf.feature_column.numeric_column('Contribution', dtype=dtypes.float32), tf.feature_column.embedding_column( tf.feature_column.categorical_column_with_vocabulary_list( 'ServiceType', [ 'SM0', 'SM1', 'SM2', 'SM3', 'SM4', 'SM5', 'SM6', 'SM7', 'SM8', 'SM9', 'SM10', 'SM11', 'SM12', 'SM13', 'SM14', 'SM15', 'SM16', 'SM17', 'SM18', 'SM19', 'SM20', 'SM21', 'SM22', 'SM23' ], dtype=dtypes.string ), dimension=16 ), tf.feature_column.embedding_column( tf.feature_column.categorical_column_with_vocabulary_list( 'Percentile', ['i_low', 'low', 'mid', 'high'], dtype=dtypes.string ), dimension=16 ), tf.feature_column.numeric_column('Time', dtype=dtypes.int8) ] model = tf.estimator.DNNRegressor( hidden_units=[64, 32], feature_columns=feature_columns, model_dir=os.getcwd() + "\job", label_dimension=1, weight_column=None, optimizer='Adagrad', activation_fn=tf.nn.elu, dropout=None, input_layer_partitioner=None, config=RunConfig( master=None, num_cores=4, log_device_placement=False, gpu_memory_fraction=1, tf_random_seed=None, save_summary_steps=100, save_checkpoints_secs=0, save_checkpoints_steps=None, keep_checkpoint_max=5, keep_checkpoint_every_n_hours=10000, log_step_count_steps=100, evaluation_master='', model_dir=os.getcwd() + "\job", session_config=None ) ) print('Training...') model.train(input_fn=get_input_fn('train'), steps=100000) print('Evaluating...') model.evaluate(input_fn=get_input_fn('test'), steps=4000) print('Predicting...') prediction = model.predict(input_fn=get_input_fn('predict')) print(list(prediction)) 的计算方法如下:

input_fn

输出如下:

def split_input():
    data = pd.read_csv('C:\\all_data.txt', sep='\t')

    x = data.drop('Result', axis=1)
    y = data.Result

    return train_test_split(x, y, test_size=0.2, random_state=123)


def get_input_fn(input_fn_type):
    train_x, test_x, train_y, test_y = split_input()

    if input_fn_type == 'train':
        return tf.estimator.inputs.pandas_input_fn(
            x=train_x,
            y=train_y,
            num_epochs=None,
            shuffle=True
        )
    elif input_fn_type == 'test':
        return tf.estimator.inputs.pandas_input_fn(
            x=test_x,
            y=test_y,
            num_epochs=1,
            shuffle=False
        )
    elif input_fn_type == 'predict':
        return tf.estimator.inputs.pandas_input_fn(
            x=pd.DataFrame(
                {
                    'Amount': 52050.00,
                    'Contribution': 1394.00,
                    'ServiceType': 'SM0',
                    'Percentile': 'i_low',
                    'Time': 5
                },
                index=[0]
            ),
            num_epochs=1,
            shuffle=False
        )

为什么模型不能学习数据?我尝试过不同的回归量并输入规范化,没有任何工作。

1 个答案:

答案 0 :(得分:1)

tf.contrib.learn.DNNRegressor隐藏了太多细节,如果所有内容都能立即正常工作,那就太棒了,但是当它需要一些调试时非常令人沮丧。

例如,学习率太大很可能。您无法在代码中看到学习率,因为它是由DNNRegressor选择的。默认情况下,it's 0.05,这对于许多应用程序来说是合理的,但在您的特定情况下可能太大。我建议您自己实例化优化程序AdagradOptimizer(learning_rate)并将其传递给DNNRegressor

初始权重也可能太大。 DNNRegressor使用tf.contrib.layers.fully_connected图层而不覆盖 weights_initializerbiases_initializer。和以前一样,默认值非常合理,但是如果你想要它不同,你根本无法控制它。

我通常做的是检查神经网络是否至少在某种程度上起作用,将训练集减少到几个例子并尝试过度拟合神经网络。这个实验非常快,所以我可以尝试各种学习率和其他超参数来找到最佳点,然后转到更大的数据集。

进一步排除故障:在tensorboard中可视化每层激活的分布,渐变或权重的分布,以缩小问题范围。