XTrainTransf = dataset.XTrainTransf XTestTransf = dataset.XTestTransf lambda_opt = {"alpha": 67.1590893061} #model_list = {ISTA(), FISTA(), Shooting(), ADMM()} model_list = {modifiedShooting(DistanceCorrelation())} ext_data = ".npz" ext_model = ".pkl" folder = "AlgorithmResults/" for model in model_list: lasso = LASSOEstimator(model) lasso.set_params(**lambda_opt) lasso.fit(XTrainTransf,YTrain) y_pred_test = lasso.predict(XTestTransf) mse_test = mean_squared_error(YTest, y_pred_test) print ("mse_test "+model.__class__.__name__,mse_test) y_pred_train = lasso.predict(XTrainTransf) mse_train = mean_squared_error(YTrain, y_pred_train) print("mse_train "+model.__class__.__name__,mse_train) np.savez(folder+model.__class__.__name__+ext_data, XTrain=XTrain, YTrain = YTrain, mse_test=mse_test, XTest=dataset.XTest, YTest = YTest, y_pred_test=y_pred_test, XTrainTransf=XTrainTransf, XTestTransf=XTestTransf, mse_train = mse_train) joblib.dump(lasso, folder+model.__class__.__name__+'_model'+ext_model, compress=9)
ext_model = ".pkl" for model in model_list: lasso = LASSOEstimator(model) clf = GridSearchCV(lasso, parameters, fit_params = {"verbose" : False}, cv=3, scoring="mean_squared_error") clf.fit(current_train, YTrain) lambda_opt = clf.best_params_ if verbose: print("best lambda", lambda_opt) lasso.set_params(**lambda_opt) lasso.fit(current_train,YTrain) y_pred_train = lasso.predict(current_train) mse_train = mean_squared_error(YTrain, y_pred_train) if verbose: print("mse_train "+model.__class__.__name__,mse_train) y_pred_test = lasso.predict(current_test) mse_test = mean_squared_error(YTest, y_pred_test) if verbose: print ("active_set", active_set, "mse_test "+model.__class__.__name__,mse_test) mses.append(mse_test) beta = lasso.beta beta_zero = np.where(np.abs(beta)<0.1)[0] ordered_indexes_zeros = ordered_indexes[beta_zero]