19 lines
569 B
Python
19 lines
569 B
Python
import json
|
|
from main import RunResults, Iteration, Centroid
|
|
|
|
|
|
def run_result_from_dict(d: dict, filename: str) -> RunResults:
|
|
centroids_d = d["centroids"]
|
|
iterations_d = d["iterations"]
|
|
return RunResults(
|
|
k=d["k"],
|
|
iterations=[Iteration(**iter_d) for iter_d in iterations_d],
|
|
centroids=[Centroid(**cent_d) for cent_d in centroids_d],
|
|
filename=filename,
|
|
)
|
|
|
|
|
|
def load_model(filename: str) -> RunResults:
|
|
with open(filename, mode="r") as f:
|
|
return run_result_from_dict(json.load(f), filename)
|