Beispiel #1
0
        "estimator,iter_num,n_selected_var,recall,precision,f1_score,exec_time\n"
    )

for data in dataset_names:
    data_dir = os.path.join('Simulation_Data', data)
    beta = np.load(os.path.join(data_dir, 'beta0.npy'))

    for iter_num in range(n_iter):
        print(iter_num)
        X = np.load(os.path.join(data_dir, f'x_tr{iter_num}.npy'))
        y = np.load(os.path.join(data_dir, f'y_tr{iter_num}.npy'))

        start_time = time.time()

        lasso = glmnet.ElasticNet(alpha=1,
                                  standardize=True,
                                  fit_intercept=False,
                                  n_splits=5,
                                  scoring='mean_squared_error',
                                  n_jobs=-1,
                                  random_state=random_state)
        lasso.fit(X, y)

        end_time = time.time()

        record.record_result(record_path,
                             method,
                             beta,
                             beta_hat=enet.coef_,
                             exec_time=end_time - start_time)
Beispiel #2
0
    for iter_num in range(n_iter):
        print(iter_num)
        X = np.load(os.path.join(data_dir, f'x_tr{iter_num}.npy'))
        y = np.load(os.path.join(data_dir, f'y_tr{iter_num}.npy'))
    
        start_time = time.time()
         
        model = PrecisionLasso()
        model.setLogisticFlag(False)
        model.calculateGamma(X)
        min_mse = np.inf
        min_lam = 0
        for i in range(11):
            lam = 10**(i-5)
            model.setLambda(lam)
            model.setLearningRate(1e-6)
            mse = 0
            for Xtrain, ytrain, Xtest, ytest in KFold(X, y, 5):
                model.fit(Xtrain, ytrain)
                pred = model.predict(Xtest)
                mse += np.linalg.norm(pred - ytest)
            if mse < min_mse:
                min_mse = mse
                min_lam = lam
        model.setLambda(min_lam)
        model.fit(X, y)
        
        end_time = time.time()
        
        record.record_result(record_path, method, beta, beta_hat=model.getBeta(), exec_time=end_time-start_time)