コード例 #1
0
ファイル: automodel.py プロジェクト: MarcelCode/talos
    def _create_input_model(self, x_train, y_train, x_val, y_val, params):

        import wrangle as wr

        from tensorflow.keras.models import Sequential
        from tensorflow.keras.layers import Dropout, Flatten
        from tensorflow.keras.layers import LSTM, Conv1D, SimpleRNN, Dense, Bidirectional

        model = Sequential()

        if params['network'] != 'dense':
            x_train = wr.array_reshape_conv1d(x_train)
            x_val = wr.array_reshape_conv1d(x_val)

        if params['network'] == 'conv1d':
            model.add(Conv1D(params['first_neuron'], x_train.shape[1]))
            model.add(Flatten())

        elif params['network'] == 'lstm':
            model.add(LSTM(params['first_neuron']))

        if params['network'] == 'bidirectional_lstm':
            model.add(Bidirectional(LSTM(params['first_neuron'])))

        elif params['network'] == 'simplernn':
            model.add(SimpleRNN(params['first_neuron']))

        elif params['network'] == 'dense':
            model.add(
                Dense(params['first_neuron'],
                      input_dim=x_train.shape[1],
                      activation='relu',
                      kernel_initializer=params['kernel_initializer']))

        model.add(Dropout(params['dropout']))

        # add hidden layers to the model
        from talos.model.hidden_layers import hidden_layers
        hidden_layers(model, params, 1)

        # get the right activation and last_neuron based on task
        from talos.model.output_layer import output_layer
        activation, last_neuron = output_layer(self.task,
                                               params['last_activation'],
                                               y_train, y_val)

        model.add(
            Dense(last_neuron,
                  activation=activation,
                  kernel_initializer=params['kernel_initializer']))

        # bundle the optimizer with learning rate changes
        from talos.model.normalizers import lr_normalizer
        optimizer = params['optimizer'](
            lr=lr_normalizer(params['lr'], params['optimizer']))

        # compile the model
        model.compile(optimizer=optimizer,
                      loss=params['losses'],
                      metrics=self.metrics)

        # fit the model
        out = model.fit(
            x_train,
            y_train,
            batch_size=params['batch_size'],
            epochs=params['epochs'],
            verbose=0,
            callbacks=[self.callback(self.experiment_name, params)],
            validation_data=[x_val, y_val])

        # pass the output to Talos
        return out, model
コード例 #2
0
_null = wr.col_corr_ols(df.head(50), 'bouncerate1', 'bouncerate1')
_null = wr.col_drop_outliers(df, 'bouncerate1', threshold=1)
_null = wr.col_fill_nan(df, 'admin_city')
_null = wr.col_groupby_cdf(df, 'bouncerate1', 'adnetworks', ascending=True)
_null = wr.col_groupby_pdf(df, 'bouncerate1', 'adnetworks', ascending=False)
_null = wr.col_groupby_stats(df_cont_cat, 'bouncerate1', 'binary')
_null = wr.col_impute_nan(df.bouncerate1)
_null = wr.col_move_place(df, 'bouncerate1', 'first')
_null = wr.col_move_place(df, 'bouncerate1', 'last')
_null = wr.col_resample_equal(df.head(50), 'adnetworks', 1)
# _null = wr.col_resample_interval() # No datetime column
_null = wr.col_rescale_max(df.bouncerate1.values)
_null = wr.col_to_biclass(df, 'category', 'NEWS_AND_MEDIA')
_null = wr.col_to_binary(df, 'bouncerate1')
_null = wr.col_to_buckets(df, 'bouncerate1', 4)
_null = wr.col_to_cols(df[['adnetworks', 'bouncerate1']].reset_index(),
                       'adnetworks', 'index')
_null = wr.col_to_multilabel(df, 'category')
_null = wr.col_to_split(df.head(10), 'top_downstream', sep='.')

# test all the attributes starting with array_
_null = wr.array_random_shuffle(df[['bouncerate1', 'bouncerate2']].values,
                                df.bouncerate2)
_null = wr.array_random_weighted(df.bouncerate1.head(10), 'normal', 10)
_null = wr.array_reshape_conv1d(df.values)
_null = wr.array_reshape_lstm(df.bouncerate1, 10, 10)
_null = wr.array_split(df.values, df.bouncerate1.values, .1)
_null = wr.array_to_generator(df.values, df.bouncerate1, 20)
_null = wr.array_to_kfold(df.values, df.bouncerate1)
_null = wr.array_to_multilabel(df.head(5).adnetworks.values)