Пример #1
0
    # random_state.
    taskid = filtered_tasks_ids[j]
    X, X_train, X_test, y_train_str, y_test_str, y_train_int, y_test_int, feature_names, class_names, categorical_names, categorical_features = get_data(
        taskid, random_state=run_id)

    # nn with embedding related
    nn_with_embedding = NN_with_EntityEmbedding(
        X_train,
        y_train_int,
        categorical_features,
        categorical_names,
        class_names,
        epochs=epochs,
        batch_size=batch_size,
    )
    nn_with_embedding_loss, nn_with_embedding_score = nn_with_embedding.evaluate(
        X_test, y_test_int)
    print("nn_with_embedding prediction score: ", str(nn_with_embedding_score))
    logger.log('nn_with_embedding', taskid, run_id, nn_with_embedding_score)

    # nn related
    nn = NN(
        X_train,
        y_train_int,
        categorical_features,
        categorical_names,
        class_names,
        epochs=epochs,
        batch_size=batch_size,
    )
    nn_loss, nn_score = nn.evaluate(X_test, y_test_int)
    print("nn prediction score: ", str(nn_score))
Пример #2
0
# features and targets for training
target = ['Sales']
# features used
features = ['Store', 'DayOfWeek', 'Promo', 'Year', 'Month', 'Day', 'State']
val_ratio = 0.1
X_train, X_val, y_train, y_val = get_train_val(df_train, features, target,
                                               val_ratio)

start = time()  # get starting time
print("Fitting NN_with_EntityEmbedding...")
epochs = 10
model_nne = NN_with_EntityEmbedding(X_train, y_train, X_val, y_val, epochs,
                                    features, features_em, em_size)
end = time()  # get ending time
train_time = (end - start) / 60  # time used, minutes
val_err = model_nne.evaluate(X_val, y_val)
print("validation error MAPE: {:.4f}".format(val_err))
print("training time: {:.4f} minutes".format(train_time))

results = {}
results['feature_dimension'] = X_train.shape[1]
results['train_time'] = train_time
results['val_error'] = val_err
rs = pd.Series(results, name="NN_with_embedding")

# save performance results
res_dir = 'results/'
res_path = os.path.join(res_dir, "res_NN_with_embedding.csv")
print("Save performance results to: {}".format(res_path))
rs.to_csv(res_path)