Exemplo n.º 1
0
    def __init__(self,
                 n_inputs,
                 n_hidden_neurons=[8, 8],
                 n_outputs=1,
                 session=tf.Session()):

        self.__session = session

        self.__id = strftime("%Y%m%d%H%M%S", gmtime()) + '-ddn-porto-seguro'

        self.__input = tf.placeholder(tf.float32, [None, n_inputs],
                                      name='input')
        self.__output = tf.placeholder(tf.float32, [None, n_outputs],
                                       name='expected_output')
        self.__keep_prob = tf.placeholder(tf.float32, name='keep_prob')

        self.__input_layers = []

        self.__hidden_weights = []
        self.__hidden_biases = []
        self.__hidden_layers = []

        self.__output_weights = []
        self.__output_biases = []
        self.__output_layers = []

        self.__losses = []
        self.__optimizers = []

        self.__gini = metric.Gini()

        self.__build(n_inputs, n_hidden_neurons, n_outputs)
Exemplo n.º 2
0
    def __init__(self, n_inputs, hidden_neurons, n_outputs=1, activation_function=tf.nn.relu, session=tf.Session()):

        self.__id = strftime("%Y%m%d%H%M%S", gmtime()) + '-mlp-porto-seguro'

        self.__session = session

        self.__input = tf.placeholder(tf.float32, [None, None], name='input')
        self.__output = tf.placeholder(tf.float32, [None, n_outputs], 'output')
        self.__keep_prob = tf.placeholder(tf.float32, name='keep_prob')

        self.__weights = []
        self.__biases  = []

        self.__model = None

        self.__gini = metric.Gini()

        self.__build(n_inputs, hidden_neurons, n_outputs, activation_function)
#
# Processing input
#
print('Normalizing...')

normalization = norm.MinMax()
train_x = normalization.fit_and_normalize(train_x)
test_x = normalization.normalize(test_x)
#
# Building the model
#
print("Training...")

svm = svm.SVC()
svm.fit(train_x, train_y[:,0])
#
# Testing model
#
print("Predicting...")
test_y_hat = svm.predict(test_x)

if not is_local_train:
    print("Exporting...")
    result = test_y_hat
    df = pd.DataFrame({'id': test_id, 'target': result})
    df.to_csv('output/prediction/' + strftime("%Y%m%d%H%M%S", gmtime()) + '-svm-porto-seguro.csv', index=False, sep=',')

else:
    gini = metric.Gini()
    print(gini.calculate(test_y.T, np.array([test_y_hat])))