Exemplo n.º 1
0
import pandas as pd
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import argparse

if __name__ == '__main__':
    parser = argparse.ArgumentParser()

    group = parser.add_mutually_exclusive_group(required=True)
    group.add_argument('-w', '--weights', help='Input file to load h5 model trained weights.')
    group.add_argument('-f', '--file', help='Input file to save trained model weights.')

    parser.add_argument('-p', '--plot', action='store_true', help='Plot the latent space in a 2D scatter (if the latent space dimesion is greater than 2, PCA will be applied).')
    args = parser.parse_args()

    x, y_true = kdd.get_dataset()
    x = MinMaxScaler().fit_transform(x)

    x_train, x_test = train_test_split(x, test_size=0.2)

    original_dim = x_train.shape[1]

    batch_size = 192
    epochs = 100

    vae = Vae([original_dim, 96, 64, 32, 16])

    if args.weights:
        vae.model.load_weights(args.weights)
    else:
        vae_history = vae.model.fit(
Exemplo n.º 2
0
import numpy as np

from utils import result_info


if __name__ == '__main__':
    parser = argparse.ArgumentParser()

    group = parser.add_mutually_exclusive_group(required=True)
    group.add_argument('-l', '--load', help='File to load SVC trained model.')
    group.add_argument('-s', '--save', help='File to save SVC trained model.')

    parser.add_argument('-e', '--encode', help='Encode the training data with a Variational Autoencoder.', action='store_true')
    args = parser.parse_args()

    x, y = kdd.get_dataset()

    y = y.cat.add_categories(['anormal'])
    y[y != 'normal'] = 'anormal'

    y = y.cat.remove_unused_categories()

    x = MinMaxScaler().fit_transform(x)

    if args.encode:
        vae = Vae([x.shape[1], 96, 64, 32, 16])
        vae.model.load_weights('models/vae_full.h5')
        x, _, _ = vae.encoder.predict(x)

    x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.4)
    
Exemplo n.º 3
0
                       '--weights',
                       help='Input file to load h5 model trained weights.')
    group.add_argument('-f',
                       '--file',
                       help='Input file to save trained model weights.')

    parser.add_argument(
        '-p',
        '--plot',
        action='store_true',
        help=
        'Plot the latent space in a 2D scatter (if the latent space dimesion is greater than 2, PCA will be applied).'
    )
    args = parser.parse_args()

    x, _ = kdd.get_dataset(mode='normal')

    x = MinMaxScaler().fit_transform(x)

    x_train, x_test = train_test_split(x, test_size=0.2)

    original_dim = x_train.shape[1]

    batch_size = 48
    epochs = 100

    vae = Vae([original_dim, 64, 32, 16, 8])

    if args.file:
        vae_history = vae.model.fit(x_train,
                                    x_train,