import numpy as np from pathlib import Path import json from LWPLSR_ import LWPLSR # loading the lwplsr_inputs.json temp_path = Path("temp/") for i in ['x_train_np', 'y_train_np', 'x_test_np', 'y_test_np','x_train_np_cv1', 'y_train_np_cv1', 'x_test_np_cv1', 'y_test_np_cv1', 'x_train_np_cv2', 'y_train_np_cv2', 'x_test_np_cv2', 'y_test_np_cv2', 'x_train_np_cv3', 'y_train_np_cv3', 'x_test_np_cv3', 'y_test_np_cv3',]: globals()[i] = np.genfromtxt(temp_path / str(i + ".csv"), delimiter=',') print('CSV imported') print('start model creation') Reg = LWPLSR(x_train_np, y_train_np, x_test_np, y_test_np, x_train_np_cv1, y_train_np_cv1, x_test_np_cv1, y_test_np_cv1, x_train_np_cv2, y_train_np_cv2, x_test_np_cv2, y_test_np_cv2, x_train_np_cv3, y_train_np_cv3, x_test_np_cv3, y_test_np_cv3) print('model created. \n now fit') LWPLSR.Jchemo_lwplsr_fit(Reg) print('now predict') LWPLSR.Jchemo_lwplsr_predict(Reg) pred = ['pred_data_train', 'pred_data_cv1', 'pred_data_cv2', 'pred_data_cv3', 'pred_data_test'] json_export = {} for i in pred: json_export[i] = Reg.pred_data_[pred.index(i)].to_dict() # json_export['pred_data_train'] = Reg.pred_data_[0].to_dict() # json_export['pred_data_cv1'] = Reg.pred_data_[1].to_dict() # json_export['pred_data_cv2'] = Reg.pred_data_[2].to_dict() # json_export['pred_data_cv3'] = Reg.pred_data_[3].to_dict() # json_export['pred_data_test'] = Reg.pred_data_[4].to_dict() json_export['model'] = str(Reg.model_) # json_export['metrics'] = Reg.metrics_.to_dict() with open(temp_path / "lwplsr_outputs.json", "w+") as outfile: json.dump(json_export, outfile) print(Reg.metrics_)