예제 #1
0
def build_lstm_model(number_neurons_per_layer, l2_lambda, input_size, number_layers, dropout):
    test_model = tf_analaysis.nn_model()
    regularizer = regularizers.l2(l2_lambda)

    model_structure = [({'units': 10, 'input_shape': (None, input_size),
                         'return_sequences': True}, 'LSTM')]

    for layer_idx in range(number_layers):
        model_structure.append({'units': number_neurons_per_layer, 'activation': tf.nn.relu,
                                'kernel_regularizer': regularizer})
        model_structure.append(({'rate': dropout}, 'dropout'))

    model_structure.append({'units': 4, 'kernel_regularizer': regularizer})
    test_model.build_nn_model(hidden_layer_structure=model_structure)
    return test_model
예제 #2
0
def build_fnn_model(number_neurons_per_layer, l2_lambda, input_size, number_layers, dropout):
    # K.get_session().close()
    # K.set_session(tf.Session())

    test_model = tf_analaysis.nn_model()
    regularizer = regularizers.l2(l2_lambda)
    # model_structure = [({'units': input_size, 'input_shape': (input_size), 'activation': tf.nn.relu, 'kernel_regularizer': regularizer}, 'dense')]
    model_structure = [{'units': input_size, 'activation': tf.nn.relu, 'kernel_regularizer': regularizer, 'input_dim': input_size}]
    for layer_idx in range(number_layers):
        model_structure.append(
            {'units': number_neurons_per_layer, 'activation': tf.nn.relu, 'kernel_regularizer': regularizer})
        model_structure.append(({'rate': dropout}, 'dropout'))

    model_structure.append({'units': 4, 'kernel_regularizer': regularizer})
    test_model.build_nn_model(hidden_layer_structure=model_structure)
    # K.get_session().run(tf.global_variables_initializer())
    # test_model.model.fit()
    return test_model
예제 #3
0
                            y_test = pd.Series(y.iloc[i], [y.index[i]])
                            X_train = X.drop(X.index[i])
                            y_train = y.drop(y.index[i])

                        if USE_SIMILARITY:
                            X_train = X_train.append(X_train_censored)
                            y_train = y_train.append(y_train_censored)

                        # shuffle
                        idx = np.random.permutation(X_train.index)
                        X_train = X_train.reindex(idx)
                        y_train = y_train.reindex(idx)

                        algo_name = 'Neural Network'

                        test_model = tf_analaysis.nn_model()
                        regularizer = regularizers.l2(l2_lambda)
                        test_model.build_nn_model(hidden_layer_structure=[
                            {
                                'units': n_components,
                                'activation': tf.nn.relu,
                                'kernel_regularizer': regularizer
                            }, {
                                'units': 50,
                                'activation': tf.nn.relu,
                                'kernel_regularizer': regularizer
                            }, ({
                                'rate': dropput
                            }, 'dropout'), {
                                'units': 20,
                                'activation': tf.nn.relu,