Esempio n. 1
0
def load_data(filename):
    """Loads CSV for splitting into training and testing data.

	Parameters:
		filename : the filename of the file to load.

	Returns:
		Two lists, each corresponding to training and testing data.
	"""
    # get holdout ratio
    train_percent = par.get_holdout()
    # load into pandas dataframe
    df = pd.read_csv(filename, header=None, dtype=float)
    # normalize the data
    for features in range(len(df.columns) - 1):
        df[features] = (df[features] -
                        df[features].mean()) / df[features].std()
    train = df.sample(frac=train_percent).fillna(0.00)  # get training portion
    test = df.drop(train.index).fillna(0.00)  # remainder testing portion
    return train.values.tolist(), test.values.tolist()
	Returns:
		The neuron activation based on the summed output.
	"""
    return z if z >= 0 else 0.01 * z


if __name__ == '__main__':
    # if executed from automation script
    if len(argv) == 3:
        AUTO = bool(int(argv[2]))
    else:
        AUTO = False
    MSE, TRP, TEP = [], [], []  # set up variables to store testing data
    # load data to train and test network on
    TRAIN, TEST = io.load_data(f'../data/{argv[1]}.csv', par.get_holdout())
    # network-specific parameters
    FEATURES = len(TRAIN[0][:-1])  # number of attributes of data
    CLASSES = len({c[-1] for c in TRAIN + TEST})  # distinct classifications
    HIDDEN_SIZE = par.get_hidden_size(argv[1])
    DIMENSIONS = (HIDDEN_SIZE * (FEATURES + 1)) + (CLASSES * (HIDDEN_SIZE + 1))
    EPOCHS, AXIS_RANGE = par.get_epochs(), par.get_rand_range()
    # de-specific parameters
    POP_SIZE = par.get_de_population_size()
    CROSS_RATE, DIFF_WEIGHT = par.get_de_params(argv[1])
    # run the de-nn
    differential_evolution(DIMENSIONS, EPOCHS, POP_SIZE, AXIS_RANGE, \
     CROSS_RATE, DIFF_WEIGHT)
    if not AUTO:
        io.plot_data(EPOCHS, MSE, TRP, TEP)
    exit(0)