writer = csv.writer(open(BASE_PATH + "results_sparse.csv", "wb"), delimiter=",") writer_full = csv.writer(open(BASE_PATH + "results_full.csv", "wb"), delimiter=",") csv_header = ['Lambda', 'Lasso', 'Lasso Red', 'ElasticNet', 'ElasticNet Red', 'Graph', 'Graph Red', 'GraKe', 'GraKe Red'] writer_full.writerow(csv_header) writer.writerow(csv_header) lambda_range = [0.1, 1.1] # inclusive 1.0 n_fold = 10 n_iter = 1000 p_val = 0.05 num_examples_sparse = 40 num_examples_big = 2000 response = "PackagingCycleTime" # *************** Load Data ************** # mm = ModelManager() file_list = [BASE_PATH + "foerdern.txt", BASE_PATH + "foerdern_ind.txt", BASE_PATH + "testen.txt", BASE_PATH + "beladen.txt", BASE_PATH + "verpacken.txt"] mm.load_data(file_list) k_sem_reduced = mm.load_kernel_laplacian(BASE_PATH + "kernel.csv") k_full = mm.load_kernel_laplacian(BASE_PATH + "full_kernel.csv") k_reg_reduced = mm.load_kernel_laplacian(BASE_PATH + "p_value_kernel.csv") dependency_graph_full = mm.load_kernel_laplacian(BASE_PATH + "dependency_full.csv") dependency_graph_sem_reduced = mm.load_kernel_laplacian(BASE_PATH + "dependency.csv") index_sparse = np.ones(num_examples_sparse, dtype=bool) index_sparse = np.concatenate((index_sparse, np.zeros(mm.num_examples() - num_examples_sparse - 1, dtype=bool))) np.random.shuffle(index_sparse)
__author__ = 'martin' from learning.grakelasso import GraKeLasso, ModelManager import numpy as np lambd = 0.1 alpha = 1 num_examples = 1000 response = "TestingProduct" # *************** Load Data ************** # mm = ModelManager() mm.load_data(["../data/test.txt"]) kernel_lap = mm.load_kernel_laplacian("../data/laplacian.csv") data = mm.get_data() index_sparse = np.ones(num_examples, dtype=bool) index_sparse = np.concatenate((index_sparse, np.zeros(mm.num_examples() - num_examples - 1, dtype=bool))) np.random.shuffle(index_sparse) X_sparse = mm.get_all_features_except_response(response, index_sparse) y_sparse = data.ix[index_sparse, response] # Evaluate GraKeLasso klasso = GraKeLasso(kernel_lap.as_matrix(), alpha) rmse, avg_theta = klasso.cross_val(X_sparse, y_sparse, 10, 10000, lambd) print("MSE and Coefficient Reduction ", rmse, avg_theta)