示例#1
0
def pls_crossval(X, y, n_comp, **kwargs):
    # fits a pls model with a given number of components
    model = pls_regression(X, y, n_comp)
    # calculated score and mse from given model
    pls_scores(X, y, model)

    return model
示例#2
0
def pls_crossval(X, y, n_comp, **kwargs):

    opt_comp = optimal_n_comp(X, y, n_comp)

    opt_model = pls_regression(X, y, opt_comp)

    pls_scores(X, y, opt_model)

    return opt_model
示例#3
0
def pls_crossval(X, y, n_comp = 10, plot=False, **kargs):
    """returns a model with the optimsed number of pls components"""

    # returns n_comp with lowest loss
    opt_comp = optimal_n_comp(X, y, n_comp, plot=plot)

    # performs regression with n_comp
    opt_model = pls_regression(X,y, opt_comp, plot=plot)
    # returns regression scores
    pls_scores(X,y, opt_model)

    return opt_model
示例#4
0
# pip_dev0["variable_selection"].plot(wave_number, X_0)
# # %%
# pip_dev0["variable_selection"].plot_feature_importance(wave_number)

# %%
def pls_crossval(X, y, n_comp, **kwargs):

    opt_comp = optimal_n_comp(X, y, n_comp)
    variance_explained(X, y, n_comp)

# %%
pls_crossval(**data_en0, n_comp=15)

# %%

model_0 = pls_regression(**data_en0, n_comp=3, plot=False)

cv_benchmark_model(**data_en0, model=model_0, y_unscaled=y, ref=ref, plot=True)


val_regression_plot(**data_en0, model = model_0)


# %%
pls_opt_0 = PLSOptimizer()

pls_opt_0.fit(X_train_0, y_train, max_comp=2)
# transformation pipeline
# %%

pip_dev1 = Pipeline(
示例#5
0
pls_opt.fit(X_train_0, y_train, max_comp=20)
pls_opt.plot(wave_number, X_train_0)
# %%
X_train_sel = pls_opt.transform(X_train_0)
X_test_sel = pls_opt.transform(X_test_0)

data_sel = {
    "X": X_train_sel,
    "y": y_train,
    "X_test": X_test_sel,
    "y_test": y_test
}


# %%
def pls_crossval(X, y, n_comp, **kwargs):

    opt_comp = optimal_n_comp(X, y, n_comp)

    opt_model = pls_regression(X, y, opt_comp)

    pls_scores(X, y, opt_model)

    return opt_model


pls_crossval(X_train_sel, y_train, 10)
model = pls_regression(**data_sel, n_comp=2)

cv_benchmark_model(**data_sel, model=model, y_unscaled=y, ref=feat_ref)
示例#6
0
mase_2, comp_2 = mse_minimum(X_test_0, y_test, plot=False)
extra_plot_mse(mse, comp, mase_2, comp_2)
# %%
# variance explained and MSECV for train and test set for each component
var, comp = variance_explained(X_train_0_sel, y_train, plot=False)
var_2, comp_2 = variance_explained(X_test_0_sel, y_test, plot=False)
extra_plot_variance_explained(var, comp, var_2, comp_2)

mse, comp = mse_minimum(X_train_0, y_train, plot=False)
mase_2, comp_2 = mse_minimum(X_test_0, y_test, plot=False)
extra_plot_mse(mse, comp, mase_2, comp_2)


# %%

model_0 = pls_regression(**data_en0, n_comp=5, plot=False)
print_cv_table(**data_en0, model=model_0)


# %%

cv_benchmark_model(**data_en0, model=model_0, y_unscaled=y, ref=ref, plot=True)
#val_regression_plot(**data_en0, model=model_0)
#val_regression_plot(**data_en_sel, model=model_sel)

# %%

model_sel = pls_regression(**data_en_sel, n_comp=2, plot=False)
print_cv_table(**data_en_sel, model=model_sel)

cv_benchmark_model(**data_en_sel, y_unscaled=y, ref=ref, model=model_sel)
示例#7
0
    return opt_model


# %%

variance_explained(X_train_en, y_train, n_comp=20, plot=True)
variance_explained(X_train_pip, y_train, n_comp=20, plot=True)

# %%




# %%

model_en = pls_regression(**data_en, n_comp =3)


model_pip = pls_regression(**data_pip, n_comp =2)

# %%
 def print_regression_table(X, y, X_test, y_test, model, y_unscaled, ref):

     print_nir_metrics(X, y, X_test, y_test, model, y_unscaled, ref)
     print_regression_benchmark(X, y, X_test, y_test, model)
     print_cv_table(X, y, X_test, y_test, model)

print_regression_table(**data_en, model=model_en, y_unscaled=y, ref=ref)

# %%