Skip to content
Snippets Groups Projects
LWPLSR_Call.py 1.03 KiB
Newer Older
import numpy as np
from pathlib import Path
import json
from LWPLSR_ import LWPLSR
import os

# loading the lwplsr_inputs.json
temp_path = Path("temp/")
data_to_work_with = ['x_train_np', 'y_train_np', 'x_test_np', 'y_test_np']
temp_files_list = os.listdir(temp_path)
for i in temp_files_list:
    if 'fold' in i:
        data_to_work_with.append(str(i)[:-4])
dataset = []
for i in data_to_work_with:
    dataset.append(np.genfromtxt(temp_path / str(i + ".csv"), delimiter=','))
print('CSV imported')
print('start model creation')
Reg = LWPLSR(dataset)
print('model created. \nnow fit')
LWPLSR.Jchemo_lwplsr_fit(Reg)
print('now predict')
LWPLSR.Jchemo_lwplsr_predict(Reg)

print('export to json')
pred = ['pred_data_train', 'pred_data_test']
Nicolas Barthes's avatar
Nicolas Barthes committed
for i in pred:
    json_export[i] = Reg.pred_data_[pred.index(i)].to_dict()
json_export['model'] = str(Reg.model_)
json_export['best_lwplsr_params'] = Reg.best_lwplsr_params_
with open(temp_path / "lwplsr_outputs.json", "w+") as outfile:
    json.dump(json_export, outfile)