nhamid289's picture
Deploy decision_boundary: two-tab panel, dataset popup, All settings popup
cf8ab7a verified
Raw History Blame Contribute Delete
1.4 kB
import type { ModelSpec, ParamSpec } from "@elvis/ui";
import spec from "../../../backend/src/models.json";
import generated from "../../../backend/src/sklearn_params.json";
// The models students can choose, from the spec shared with the Python backend:
// models.json picks the settings shown first, sklearn_params.json has the rest.
// JSON imports type "kind" as string, so the specs' shape is checked by
// backend/tests/test_models.py rather than here.
const allParams = generated.models as unknown as Record<string, ParamSpec[]>;
export const MODELS: ModelSpec[] = spec.models.map((model) => {
const shown = new Set(model.params.map((p) => p.name));
const library = allParams[model.id] ?? [];
const described = new Map(library.map((p) => [p.name, p.description]));
return {
...(model as unknown as ModelSpec),
// The panel's settings take their description from scikit-learn's too
params: (model.params as unknown as ParamSpec[]).map((p) => ({ ...p, description: p.description ?? described.get(p.name) })),
// Arguments models.json always passes (e.g. max_iter) start at that value
otherParams: library
.filter((p) => !shown.has(p.name))
.map((p) => (p.name in model.fixed ? { ...p, default: model.fixed[p.name as keyof typeof model.fixed] } as ParamSpec : p)),
libraryDefaults: Object.fromEntries(library.map((p) => [p.name, p.default])),
};
});