Editing a Fitted Model#
The SuperGLM editor is a compact analyst workspace for reviewing and adjusting fitted one-dimensional effects. Python owns the fitted model, edit history, summaries, and evidence; the browser provides a fast visual preview and sends completed actions back to Python.
Open the Editor#
Create an editor session from a fitted model and display its widget in Jupyter or VS Code:
from superglm.editor import EditorSession
session = EditorSession.from_model(
model,
terms=["age", "territory"],
train_data=(X_train, y_train, w_train),
validation_data=(X_val, y_val, w_val),
)
session.widget()
superglm.editor.edit(model, ...) takes the same arguments and returns the same kind of session.
Each data argument is a tuple (X, y), (X, y, sample_weight) or (X, y, sample_weight, offset):
train_datais the data the model was fit on. Refit, the rating table and Final fit use it. Without it they use the fit data the model kept, if it kept any.validation_datais scored on the metric strip and in the Validation report. Final fit also trains on these rows.test_datais scored in the Validation report. Final fit never trains on it.cvis across_validateresult for the Cross-validation tab, andcv_dataholds the rows its folds were drawn on. See Cross-validation.termslimits the editor to the named features. Leave it out to edit every feature.
The standard iframe is 1180 by 720 pixels. At narrower notebook widths the inspector becomes a drawer; in a short window the workspace scrolls instead of shrinking the plot into an unusable strip.
Which models open, and what a curve shows#
The editor opens every fitted SuperGLM, whatever its family and link, and every SuperLSS
family except DirichletLSS, whose response is a set of shares rather than one number. A
SuperLSS parameter can be on any link, its default or one you chose.
Each curve is the term’s contribution to one linear predictor, and what the chart draws follows the link that predictor was fitted on:
The term’s link |
The curve shows |
No effect |
An edit changes |
|---|---|---|---|
log |
the relativity: the factor the term multiplies its parameter by |
1.00 |
the relativity |
log with a floor (the log-normal’s σ) |
the relativity of the parameter above its floor |
1.00 |
the relativity |
logit |
the relativity of the odds |
1.00 |
the odds relativity |
identity |
the amount the term adds, in the parameter’s units |
0 |
the amount added |
any other (inverse, probit, cloglog, square root, a power or a bounded link) |
the effect on the link scale |
0 |
the effect on the link scale |
The negative binomial’s θ is the one exception: its curve is the relativity of the overdispersion, 1/θ, so it rises where overdispersion rises. The axis label says which quantity a curve shows, for example relativity of the CV, effect on the mean or effect on the probit scale of the mean, and the Cross-validation tab draws the same values.
The Explain tab draws log-normal (mean form), gamma, negative binomial and Tweedie models on their usual links, and the distribution panel the same families except the negative binomial, whose counts it does not draw; for other families they say so, and the rest of the editor works. The rating table and its preview multiply factors, so they hold the terms on a log link.
On Databricks and other hosted notebooks#
session.widget() normally serves the editor from a small web server on the machine that runs
Python, and the notebook shows that page. On a hosted notebook such as Databricks, your browser
cannot reach that machine, and the page shows “refused to connect”. Run the editor inside the
notebook cell instead. It needs one extra package, which a notebook cell installs with
%pip install "superglm[notebook]":
from superglm.editor import EditorSession
session = EditorSession.from_model(model, train_data=(X_train, y_train, w_train))
session.widget(mode="notebook")
On Databricks, once the package is installed, session.widget() picks this mode by itself; without
it, the editor keeps its web server and warns with the install line. Use mode="notebook" on any other
notebook whose browser is not on the machine running Python, such as a remote JupyterHub, and
mode="server" to keep the web server where both run on one machine.
The editor behaves the same in either mode, with four differences:
It answers only while the notebook is idle, so it waits while another cell runs.
Export downloads through the browser, which some workplaces block. Save to Kernel Path writes the file on the cluster instead, for example to a Unity Catalog volume such as
/Volumes/catalog/schema/volume.Open Folder is not offered, because the folder is on the cluster rather than on your computer.
Each change travels to Python as one notebook message, which carries at most 4 MB. A larger one, such as a very long History note, is refused with a message saying so; make it in smaller steps or in Python on the session.
Databricks’ dark theme inverts the colours of every cell’s output. The editor undoes that, so its Day and Night themes look as they do anywhere else, and Follow the browser follows the Databricks theme.
Find a Feature#
The feature list on the left names every term in the editor, grouped as the chart groups them, with each term’s kind and effective degrees of freedom. The current term is highlighted.
Type in the search box to filter the list. Enter opens the first match and Escape clears the search.
The arrow keys step between features; Enter or a click opens one.
The toggle at the top collapses the list to a thin strip that names the current term, so the plot keeps its width. The editor remembers your choice.
In a window narrower than about 1280 pixels, the list starts collapsed until you open it.
Select, Move, Zoom, and Handles#
Select picks points or levels:
Click a point to select it.
Shift-click another point to select every point between the two, by position along the axis, whatever their heights.
Ctrl-click (Cmd-click on a Mac) adds or removes one point, on any term.
The point clicked last, with or without Ctrl or Cmd, is where the next Shift-click starts.
A click on the curve between two points selects the nearest point. A click on empty space changes nothing.
Drag a box to select the points inside it. Select all selects the whole term.
Move drags selected relativities. The curve previews immediately and Python confirms the edit when the pointer is released.
Zoom drags a box, and the mouse wheel zooms around the pointer. In the other tools the wheel scrolls the page when there is more below the chart, so hold Ctrl or Cmd with the wheel, or pinch, to zoom there. Shift-drag or a middle-button drag pans, and Home restores the fitted extent.
Handles edits a spline through fixed-x control handles. In Handles mode, when the fitted term exposes its basis, Contrib shows each basis function’s contribution and Build animates them into the spline. Settings sets how long Build takes.
The active mode is always visible in the mode switch at the left of the chart’s toolbar. Hover briefly over an icon, or focus it with the keyboard, to see its name and shortcut.
Ordered Categorical Splines#
An ordered categorical fitted with a spline basis, such as
OrderedCategorical(order=..., basis=Spline(...)), is drawn as its spline, with a dot on each
level. Special levels (specials=) are drawn as separate dots.
Handles works as it does on a numeric spline. Each handle is one spline coefficient, and moving it sets every level to the spline the handles draw, so a handle can sit off the curve.
Special levels do not move with the handles.
Contrib and Build show the spline’s basis between the levels.
Handles is off while some of the term’s levels are collapsed into a group.
Handles is off while the term holds a shaped range.
When Handles is off, hover over it to see the reason.
See a Spline Without Its Smoothing#
The Unsmoothed icon in the chart’s toolbar draws a spline term fitted again with its smoothing switched off, as a solid green line over the curve, with unsmoothed in the legend. On an ordered term, Free levels does this job instead: see Compare with free levels.
The model is fitted again with the term’s smoothing at zero, on the same knots. Every other term keeps the smoothing the model chose for it.
The line is drawn under the same centring as the curve. Each is centred on its own fit, so the two need not meet.
The line is one fit per term. The icon is busy while it runs, and you can go on editing.
The choice stays on as you move between spline terms, until you turn it off.
Hand edits keep the line. A refit fits it again.
A spline needs rows under each of its basis functions to be fitted without smoothing. Across a gap in the data it has none there, so no line is drawn, and the icon stays on. Hover over it for the reason. Fewer knots, or knots where the rows are, fix it.
A line far from the curve does not squash the chart: past the curve’s own range again above and below, it runs off the plot.
Curve Selection Operations#
The floating palette acts on the current selection:
Increase or decrease moves the selected relativities by five percent. On a curve of added effects (identity and other links) the step is five percent of the size of the linear predictor on an average training row, so on an identity link it moves an average row by about what five percent would.
Smooth reduces local variation while respecting adjacent unselected values.
Straighten selection interpolates the selected relativities between their first and last points.
Increasing and Decreasing replace the selection with the closest monotone curve, weighted by exposure. It is not tied to the points either side, so it can leave a step at an edge.
Level left, Average, and Level right flatten the selection to the named reference value.
Snap highest and Snap lowest flatten to the selected extreme.
The icons remain compact so the plot stays large. Their delayed hover and immediate focus explanations describe the action before it is run.
Waiting Changes and Refit#
Collapse, Ungroup, Set reference, Make special, Back on the curve, the four shapes (Flat, Line, Quadratic and Cubic) and knot changes change the structure of a term, so the model must be refit before they take effect. They do not refit one by one: each change waits, and Refit in the application bar applies every waiting change in one fit.
While changes wait:
the chart draws them over the last refit’s curve: a waiting group is named on a dashed bracket under the axis, with its members’ bars dashed in the group’s colour, and a waiting range is a dashed box tagged “waiting for refit”;
the curve, the metrics and the summary still describe the last refit;
the feature list marks each term that has a waiting change with an amber dot;
the Refit button shows how many changes wait;
the status line under the chart starts with the count, for example “2 changes waiting for refit”.
Choose Refit, or press R, to apply them. The refit is one step in the history:
Hand edits on terms whose structure did not change are put back on the refitted model. Putting them back is one more history entry, “Hand edits carried over: DrivAge, VehAge”, and Undo of that entry returns those terms to the refitted curves.
Hand edits on a term that a waiting change restructures are dropped. Undo brings them back.
If the fit is refused, the model and the waiting changes stay as they were, and the message says to undo the last waiting change and try again.
To refit after every change instead, turn on Refit after every structural change in Settings. Each change then refits straight away, and one Undo takes it back. The heading over these icons in the selection palette reads Structure while changes wait for Refit, and Refit while each one refits at once.
From Python, session.stage_structural(...) makes a change wait and session.refit_pending()
applies every waiting change; choose Refresh from Python to see them in the browser.
Group and Ungroup Categorical Levels#
Expanded and Collapsed display modes change only how an existing fitted grouping is drawn. They do not rename levels or change the fitted model. Groups shown as, in Settings, chooses the mode a term opens in.
Select levels and choose Collapse to combine them into one group, named after its members, for
example B10+B11. Select grouped levels and choose Ungroup to separate them again. Both wait
for Refit; see Waiting Changes and Refit.
With Keep the reference level when collapsing on in Settings, which is the default, the reference stays where it is:
Collapsing other levels leaves the reference level as it is.
Collapsing the reference level into a group makes that group the reference.
Ungrouping some levels out of the reference group leaves the reference with the levels that stay grouped.
The reference chip then reads “kept”. With the setting off, a collapse or ungroup lets the term choose its reference again by its own rule, most exposed or first, so the reference can move to another level.
Long category names may appear shortened with an end ellipsis on the x-axis. This is display-only. Hover or focus the tick (or inspect the point tooltip) for the complete value; selection, grouping, history, exports, and saved models retain the exact original string.
Set a Reference Level#
The reference level is the one whose relativity is 1.00. A chip beside the term’s kind and EDF names it and says how it was chosen: most exposed, first, pinned, or kept through a collapse or ungroup.
To pin a different level, select exactly that one level and choose Set reference in the selection palette. It waits for Refit, and until then the chip shows the waiting choice, for example “reference B3 · waiting”.
Predictions stay the same unless the model has a selection penalty.
If the term rates unseen levels at the reference, their rate moves with it.
In the Collapsed display, selecting a whole group pins the group.
Special levels of an ordered term cannot be the reference.
A term used by an interaction cannot change its reference.
Special Levels of an Ordered Term#
An ordered term’s curve smooths each level toward its neighbours. A level that is different in kind,
such as a missing-value band or a level with a structural zero, can be taken off the curve as a
special level, with an estimate of its own, as OrderedCategorical(specials=[...]) declares in
code.
Compare with free levels#
To see which levels the smoothing overrides, choose Free levels in the chart’s toolbar. The model is fitted again with the term’s levels all free, as a plain categorical with the same groups and reference, and each level is drawn behind the curve as a green diamond at its relativity to the reference, the diamonds joined by a green line. The reference’s diamond sits at 1, as in a categorical’s output. One button turns both on and off.
Each diamond’s 95% interval against the reference shows while Reference CI is on, as a green whisker through the diamond. The free series sits just right of each level, so its intervals stand beside the curve’s own, in blue with caps through the curve’s points. The reference has neither: it is 1 by definition.
The free interval is usually the wider: each level is estimated from its own rows alone, while the curve borrows strength from its neighbours, most of all beside the reference.
A level the smoothing overrides has its diamond filled in: the curve holds it away from what its own data says. It is marked whether the intervals show or not.
That judgement compares the free fit with the curve after centring both on the levels’ exposure-weighted average, not at the reference. Otherwise a curve that misses the reference itself would mark nearly every level. So a filled diamond need not have its whisker miss the curve, and a whisker that misses the curve need not be filled.
The judgement allows for the curve’s own pull toward each level. A model fitted with
retain_fit_state=Falsekeeps nothing to measure that pull, so the judgement allows for any correlation between the curve and the free estimate, which makes it stricter, and a note says so.The judgement is widened for the number of levels compared, so a filled diamond is rarely chance.
Each level is judged on its own. Making one level special moves the curve, and with it the other levels’ marks.
A level with little exposure has a wide interval. The smoothing helps such a level, so leave it on the curve. It does not move the other levels’ marks.
Some levels have no free value to draw, and get no diamond; a note names them:
a level whose every response is 0, such as a band with exposure but no claims, or, for a yes/no response, every response 1;
a level whose rows another term covers exactly, such as a categorical with one level for just those rows.
The judgement also allows for any correlation between the two fits, and a note says why, when the session’s training data holds the model’s rows in another order or other rows, when the family and link leave the pull unmeasured where rows sit far from their fitted mean (a Gaussian response with a log link, say), when the model has a shape-constrained P-spline, when a curve’s binding constraints cross a level of almost no weight, or when the fit cannot be measured for another reason the note gives.
No level is judged, and a note says why, when either fit stops before it converges (raise the model’s
max_iter), or when a custom penalty removes the term from the free fit, which then draws its levels flat.The comparison is one more fit, like Refit, and holds the editor while it runs.
It stays on the chart until you choose another term or the model changes.
Turned off and on again for the same term and model, it comes back at once, with no new fit.
A level with no free value, named in the note, leaves a gap in the line. If the reference has none, the levels are drawn by their gap from the curve instead, and the note says so.
If the model has a selection penalty, it is lifted from this term for the comparison, so the free levels are not shrunk. The other terms keep theirs. A custom penalty that cannot be limited to some terms shrinks the free levels too, or removes them, and the legend then says so.
Hand edits are not part of either side: the curve and the free levels are both fits.
Make special and Back on the curve#
Select one or more levels on the curve and choose Make special in the selection palette. It waits for Refit, with a dashed ring round each level. After the refit the levels sit apart from the curve, each with its own estimate.
The reference stays on the curve: set another reference first.
A level in a group cannot be made special: ungroup it first.
A level with no rows in the data cannot be made special: it has nothing to estimate from.
A level where a shaped range starts or ends, or a stated knot or break, stays on the curve: move or remove the range first.
At least two levels must stay on the curve.
To put special levels back, select them and choose Back on the curve. Each goes back to its place in the order.
A level declared special in the term’s code has no place on the curve, so Back on the curve is unavailable for it. Change the declaration instead.
As with other structural changes, hand edits on the term are dropped by the refit, and Undo brings them back.
Run CV on the current model afterwards to check that the change holds up across the folds. Structure files record the special levels, so the next model can make the same levels special.
Where New Levels Go#
When a model predicts, it can meet a level its fit never saw, such as a brand added after the fit. On a categorical term, New levels → in the bar above the chart chooses what prediction does with such a level:
Refuse stops the prediction with an error that names the level. This is the default.
Reference rates it at the reference level, relativity 1.00, and warns, naming the level.
A group, listed by its name, gives it that group’s relativity, and warns, naming the level.
The choice changes predictions only. Nothing refits, the curves stay as they are, and Undo takes the choice back. History lists it as, for example, “New levels → B10+B11”. The Python model export and the Structure (JSON) export keep it.
The control is offered on unordered categorical terms only.
Only groups of two or more levels are listed.
It is disabled while a change to the same term waits for Refit. Refit or undo that change first.
It is disabled on a term used by an interaction.
A collapse or ungroup that would remove the group new levels go to is refused. Choose where new levels go first, then make the change.
A good choice is a group of thin levels. Pool the term’s thin levels into one group and send
new levels there. A new level has no rows of its own, and the pooled group’s relativity is
estimated from all the thin levels’ rows together. scikit-learn’s OneHotEncoder follows the same
rule: with handle_unknown="infrequent_if_exist", an unknown category maps to the infrequent
category, which pools the categories rarer than min_frequency, if it exists
(scikit-learn documentation).
In the editor, select the thin levels, choose Collapse and Refit, then choose the new group
under New levels →. In Python you can name the group yourself, such as “Other”; see
Unseen levels at predict time.
A RandomEffect term needs no choice: it already gives a level it never saw the population
average.
Shape a Range#
A shape pins part of a spline term to a simple polynomial while the rest of the term stays the fitted smooth. It works on numeric spline terms and on ordered terms with a spline basis, of a SuperGLM or of any parameter of a SuperLSS.
In Select mode, select points, or bands on an ordered term. The range runs from the first selected point to the last, so a Shift-click span or points picked with Ctrl-click both work.
Choose one of the four shape icons in the selection palette: Flat, Line, Quadratic or Cubic. The toggle beside them sets how the curve meets the range at each edge: Tangent (the default) leaves the shape along its slope, Corner lets the slope change there. The choice is remembered.
The shape waits for Refit, drawn as a dashed box tagged with its shape and “waiting for refit”. After the refit the range is drawn as a light band labelled with its shape; hover over it to see the shape and its edges.
On a numeric term the range runs from the first to the last selected point, widened to a round value at three significant figures of the fitted range, and never past its ends.
When no plotted point lies between the selection and a shaped range beside it, the new range starts or ends exactly on that range’s edge, so the two meet.
On an ordered term the range covers whole bands and is drawn from the first band to the last. Two ranges can share an edge band.
The curve stays continuous at each edge of the range. With Tangent it also keeps its slope there; with Corner the slope may change.
Flat fits a level to the range. To hold the curve at its value at a range’s edge instead of fitting a level, use Level from left or Level from right. That is an edit, not a refit.
To fit one polynomial over the whole axis, choose Select all and then a shape.
A term can hold several ranges, each added as its own change.
A new range paints over the ranges it overlaps. A range it covers goes. A range it overlaps at one end keeps the part outside the new range, and a range it falls inside is split in two around it. Each part keeps its shape and join and meets the new range at its edge.
Choosing a new shape on exactly the same range replaces the old shape.
The History names what a change does to the ranges it paints over, such as “Flat 85 – 110 (trims Line 97 – 150 to 110 – 150)”. Until Refit, each part a waiting change leaves is drawn as a dashed box too, and the range in force keeps its band.
Each part kept of a cut range needs as many values as any range of its shape. If one would hold too few, SuperGLM refuses the new range and names the range it would cut. Cover all of that range, or leave more of it outside the new one.
A Line needs at least two distinct values in the range, a Quadratic three and a Cubic four. On an ordered term each band is one value, and so is a collapsed group inside the range. When the selection holds too few, the icon is disabled and says so on hover.
A binned fit (
discrete=True) sees only one value for each occupied bin, so those are the values it counts. Values that share a bin count once, so four distinct values may not be enough for a Cubic. The count the palette shows is on the fitted bins, but a refit bins again on the new range’s own knots, so it can carry a shape the palette greys out, or refuse one it allows.The curve outside the ranges needs values too. If a range would leave too few between it and the end of the axis, or the next shaped range, SuperGLM refuses it and says so. Widen the range to reach the end or that range.
A range cannot start or end inside a collapsed group. Ungroup the bands at its ends first.
A range cannot take in a special level of an ordered term.
A band at the edge of a shaped range cannot be collapsed into a group.
A P-spline or natural spline term is refitted as a B-spline with the same knots and a derivative penalty, so the penalty can leave the shaped range alone. A natural spline’s curve is then no longer held straight at the ends.
The icons are hidden on an unordered categorical term. On any other term that cannot take a shape they are disabled, with the reason on hover:
The term is not a spline, such as a linear term or an ordered term without a spline basis.
The term is a cardinal cubic regression spline.
The term has a shape constraint, such as increasing or convex. Its rules are named in the term bar, such as rule increasing; hover over it to see whether edits keep to them. Edits of a SuperLSS term keep to its rules; see Editing a constrained SuperLSS term.
The term uses
select=True.The term is used by an interaction.
The summary, the Python summary() and the workbook note that shaped ranges were chosen in the
editor from this data. Tests are conditional on them, so judge them on validation deviance.
Move the Knots#
The knots of a spline are the points where its pieces join. The Knots tool moves them, adds them and removes them. It works on a numeric spline term, and on an ordered term with a spline basis.
Choose Knots in the mode switch at the left of the chart’s toolbar, or press K. The knots show as diamonds on the x-axis.
Move: drag a knot along the axis. A tag above it shows where it is. Knots may pass each other; a knot dropped too close to another moves to the nearest free spot.
Add: click the axis where the dashed diamond shows.
Remove: drag a knot below the axis, onto Drop here to remove the knot. A spline keeps at least one knot.
Keyboard: click a knot to select it. The arrow keys nudge it along the axis, ten steps at a time with Shift. Delete removes it, and Escape clears the selection.
In the Knots tool, the chart’s toolbar shows the rest:
Count (− n +): the number of knots. Hover a greyed-out button to see why it is off.
Placed by: the rule that places them. Choose Even spacing, Quantiles of values, Quantiles of rows, or Tempered quantiles with an alpha from 0 to 1. Knots placed by hand show as Hand.
Reset knots: returns the knots to the ones declared in code.
Kind: the kind of spline. Choose P-spline, B-spline, Cubic regression or Natural. The knots stay where they are. A spline declared in code as a cardinal cubic regression spline (
kind="cr_cardinal") shows as Cardinal cubic regression, which cannot be chosen.Shrink: a second penalty, on the term’s straight-line part. With it on, the fit can shrink the term towards a straight line and, where the data do not support it, out of the model. In code this is
select=True. Hover a greyed-out Shrink to see why it is off.
Changing the count or the rule places every knot again by that rule. This drops any knot you moved by hand. Undo brings them back.
A P-spline penalises the differences between neighbouring coefficients. A B-spline penalises the curve’s bending itself. A cubic regression spline and a natural spline are cubic, and are held straight at each end of the data. A P-spline or B-spline takes the degree declared in code.
Outside the tool, the knots show as small ticks under the axis. While a knot change waits, the knots it places are amber. The knots it moves or removes stay as dashed grey outlines until Refit, and a removed one is crossed out.
A knot, Kind or Shrink change waits for Refit, like the other structural changes. While a Kind or
Shrink change waits, that control is amber, and History names the change, for example
kind cr in BonusMalus or shrinkage on in BonusMalus. With Refit after every
structural change on in Settings, it refits at once. Undo, Redo and Revert to original model
cover it. The refit drops hand edits on the term, as it does for every structural change. A
monotone or convex term keeps its constraint, and the refit chooses the smoothing again. Run CV
compares the edited knots with the original model.
Knot changes have these limits:
Count: an ordered term takes at most one knot fewer than the levels on its curve.
Interactions: a term used by an interaction keeps its knots, kind and shrinkage.
Evenly spaced only: a natural spline (
kind="ns"), and a P-spline whose penalty ordermis above its degree, take only evenly spaced knots. The tool shows their knots but does not move, add or remove them by hand, and Placed by offers Even spacing only. Hovering the axis says why. Their count can still change, and Reset knots still works.Waiting level changes: while a waiting change alters an ordered term’s levels, refit before you change its knots, kind or shrinkage.
Kind and Shrink have these limits too:
Shaped ranges: a term with shaped ranges takes a B-spline or a cubic regression spline only.
Shaped ranges and Shrink: a term with shaped ranges cannot shrink.
Natural splines and constraints: a natural spline takes no shape constraint.
Natural splines and Shrink: a natural spline cannot shrink.
Natural splines and knots: a natural spline takes evenly spaced knots only. Choose Even spacing under Placed by before you choose Natural.
Penalty order: a B-spline or a cubic regression spline needs a penalty order
mno higher than its degree.Penalty order and Shrink: a P-spline or B-spline shrinks only with a penalty order
mof 2 or less.Constraints and Shrink: a term whose shape constraint the fit enforces (
Constraint.fit) cannot shrink. A constraint applied after the fit (Constraint.postfit) can.
Rating-Table Preview#
The Chart / Table switch above the chart shows the current term’s block of the Excel rating table in place of its curve. It is built by the same code as Export > Excel rating workbook, on the same data, so it shows what the workbook will hold: the same rows, number formats and note.
It follows every edit and every Refit.
Like the curve, it shows the last refit: changes waiting for Refit are not in it.
It needs the training data:
train_data, or fit data the model kept. Without it the table says so.Interaction terms are not shown.
When the export refuses the model, the table shows the reason instead.
In a SuperLSS session the table is the block for the term’s own parameter. The note above it says what the factors multiply: the Mean, the CV, σ above its floor (log-normal) or overdispersion (1/θ). A parameter the export leaves out shows its reason; the others keep their tables.
Undo, Redo and Revert#
Undo and Redo, in the application bar, walk one history: every manual edit, every waiting change and every applied step (Refit, revert and a New levels → choice) in the order you made them, whichever term is on screen. Each popover names what it would undo or redo, for example Undo: Line 30–45 in age or Undo: shift age. They act on confirmed Python history, not on an uncommitted pointer preview.
Undo takes back a waiting change without refitting, and Redo puts it back.
Undo after a Refit brings its changes back as waiting. Redo applies the Refit again without fitting.
Undoing a step puts back the model, the curves, the manual edits, the level order and the selection from before it. Redo puts the step back. Neither refits.
A new edit or change clears whatever was waiting to be redone.
A distribution re-profile starts the history afresh; Undo does not reach past it.
A re-profile waits until nothing waits for Refit. Refit or undo the waiting changes first.
Revert to original model, next to Undo and Redo, goes back to the model the editor was opened with. It also undoes a distribution re-profile and clears the waiting changes. It is one more step, so Undo brings back everything it cleared.
Refresh from Python#
If you change the session in the notebook, for example collapse levels from Python, the browser does not see it straight away. Choose Refresh from Python in the application bar to re-read the session and redraw. Nothing refits.
Recovery#
If an edit request fails, the browser restores the last confirmed Python state and shows a persistent message. Choose Retry to repeat that action after recovery or Dismiss to keep the restored state. A failed metric, summary, or report refresh does not undo a valid model edit; only that evidence panel becomes Stale and offers Retry.
Evidence Freshness#
The metric strip, summary, and reports distinguish these states:
Current describes the displayed model revision.
Updating retains the last confirmed values while Python computes the new revision.
Stale retains those values after a failed refresh and must not be read as current evidence.
Error means that panel has no confirmed value to retain.
Late responses for an older model revision or request sequence are ignored. Validation and test rows remain in Python; the browser receives aggregate metrics rather than a copy of the evaluation data.
Inspector and Help#
The inspector beside the chart has four tabs: Summary, History, Settings and Help. On a narrow screen they share a dismissible drawer. Escape closes a popover or drawer and returns focus to its launcher.
Summary#
Summary shows the current model: its family, link and method, four tiles for deviance, AIC, BIC and total EDF, and a section for each term.
The search box at the top keeps the terms and levels whose names contain the text, ignoring case, highlights the matches and counts what it found. Escape clears it.
The full summary below the table is not searched.
All, Edited and Waiting show every term, the terms with hand edits, or the terms with changes waiting for Refit.
Summary follows the chart: the chart’s term opens and scrolls into view, and the others fold to one line with their kind, EDF and any waiting changes. Open any of them until the chart shows another term. A search opens every term it finds.
A spline’s folded line also shows the p-value of its whole-term test. A categorical term has no whole-term test, so its line shows none.
History and notes#
History lists the session newest first, in three parts: Waiting for refit, Applied and Undone. Each entry has a short id, the time it was made and a message written for it, such as “collapse B10 + B11 in VehBrand” or “Refit · 2 changes”.
Undo takes this marks the entry that Undo takes next.
The muted entries under Undone are what Redo would put back, top one first.
The pencil on an entry adds a note saying why. Enter, or leaving the field, saves it; Escape keeps the old one.
A note stays with its entry through Undo and Redo.
Notes are saved with the exported Python model; see Export.
A distribution re-profile starts the list afresh, as it does for Undo.
Settings#
Settings, behind the gear icon, holds preferences kept in this browser:
Refit after every structural change, off by default: each change refits at once instead of waiting for Refit.
Keep the reference level when collapsing, on by default; see Group and Ungroup Categorical Levels.
Follow the browser’s light or dark setting, on until you flip the theme switch.
Groups shown as Expanded or Collapsed when a term opens.
Build animation: how long Build takes.
Request timings: how long the last refit and each panel took.
Where the browser blocks storage, as some private windows do, the choices last until the page closes.
Help#
Help lists the modes, gestures, operations and shortcuts, in the words the icons’ hover text uses.
Theme#
The DAY / NIGHT switch in the application bar sets the light or dark theme. Until you flip it, the editor follows the browser’s light or dark setting, which inside a notebook is not always the notebook’s own theme.
A flipped switch keeps its theme through a reload of the page.
Follow the browser’s light or dark setting, in Settings, hands the theme back to the browser.
When the operating system is set to reduce motion, the switch changes without its animation.
Export#
Choose Export in the application bar, then one of four formats:
Python model downloads a fitted
.joblibartifact or writes it to a kernel path. SuperGLM loads the serialized artifact back before releasing it and, when evaluation rows are available, compares predictions on a bounded sample.Excel rating workbook writes deployment-oriented rating tables. This export needs
train_dataor fit data retained by the model. Its Model Summary sheet contains typedModelOverviewandTermInferencetables, so numbers remain numeric Excel cells rather than one large formatted text block. For a SuperLSS model it holds one sheet per parameter that has a table, then a summary; if no parameter has one, the export says why.Final fit model is the latest Final fit on all rows, from the Cross-validation tab. It is offered while the model has not changed since that fit.
Structure (JSON) writes each term’s groupings, reference, shaped ranges and where new levels go, without coefficients or hand edits. See Structure Files.
The Python model and the workbook include your hand edits. Every export except Final fit model is built from the last Refit:
Changes still waiting for Refit are not included, and the dialog says how many.
Display-only zoom, mode, grouping view, and truncated tick text are not written into the model.
The Python model carries the history, notes included, as
model._editor_history: one record per entry, with its id, time, operation, term, message, note and status.
Structure Files#
A structure file records the structural decisions made on a model, without its coefficients, so they can be built into another model and fitted on new data, such as next year’s. For each term it holds:
the groupings of its levels;
the reference level;
the shaped ranges, with their degree and join;
where new levels go;
which levels of an ordered term are special;
the knots chosen with the Knots tool, where there are any;
the kind of spline and its shrinkage, where chosen with Kind and Shrink.
Knots are recorded only where the editor chose them. Knots declared in code are not recorded. A
spline with editor knots has a knots entry. Knots moved by hand are recorded with
"strategy": "explicit" and their positions; knots placed by a rule are recorded with the rule and
their count, and applying the file places them by that rule on the data. On an ordered term the
positions are on the axis its spline is fitted over.
"DrivAge": {
"kind": "spline",
"knots": {
"knot_alpha": 0.2,
"n_knots": 6,
"positions": [21.0, 26.5, 33.0, 41.0, 52.5, 68.0],
"strategy": "explicit"
},
"ranges": []
}
A kind or shrinkage chosen in the editor is recorded in a basis entry, with the kind and whether
the term shrinks. A spline whose kind and shrinkage come from code has no basis entry.
"DrivAge": {
"basis": {"kind": "cr", "select": true},
"kind": "spline",
"ranges": []
}
Choose Export > Structure (JSON), or call session.export_structure("structure.json") from
Python. The file is JSON with sorted keys, so two versions compare cleanly in a diff.
Build it into a model and fit:
from superglm import read_structure
structure = read_structure("structure.json")
next_model = structure.apply(model, X=X_next)
next_model.fit(X_next, y_next, sample_weight=w_next)
apply returns an unfitted copy of model with those decisions in its features. The model you
pass is left unchanged, and features the file does not name are copied as they are. The copy’s
penalties and family are the ones model was declared with, even when model is fitted: a
selection_penalty="auto" is calibrated again on the new data, a
NegativeBinomial(theta="auto") estimates its theta again, and smoothing that fit_reml
estimated is not carried over, so fit the copy with fit_reml to estimate it again.
Pass
X=, the data you will fit on. A level of a grouped term that the file does not list then goes where the file sends new levels, with one warning per term.Without
X=, a level of a grouped term that the file does not list is refused when the model is fitted.With
X=, a spline whose boundary comes from the data is widened to hold a shaped range that reaches past the new data’s values, with one warning.A range the spline cannot take on the new data is refused, naming the feature and the range: by
applywhen you passX=, otherwise by the fit.A P-spline or natural spline with a shaped range is rebuilt as a B-spline, as in the editor.
A spline whose file has a
knotsentry is rebuilt with those knots. A file without one keeps the declared knots.A file with a
knotsentry needs superglm 0.40 or later. Older releases refuse it.A spline whose file has a
basisentry is rebuilt as that kind, with or without shrinkage, before its knots and ranges. It keeps its other declared settings.A
basisthe declared spline cannot take, such as a natural spline on a term with a shape constraint, is refused, naming the feature.A file with a
basisentry needs superglm 0.40 or later. Older releases refuse it.A feature the model does not have is refused, by name.
A feature that is another kind of term in the model is refused, by name.
A level the file makes special is taken off the model’s curve.
A level the model’s code declares special cannot be put on the curve by a file. It is refused, by name.
A file that names no special levels keeps only those the model’s code declares.
A level a Piecewise term with breaks stated by position would lose is refused, by name: state the breaks by band name.
Each refusal from apply is a superglm.StructureError whose message names the feature.
Cross-validation#
Pass a cross_validate result as cv= to fill the Cross-validation tab:
from sklearn.model_selection import KFold
from superglm import cross_validate
from superglm.editor import EditorSession
cv = cross_validate(
model_template, X_train, y_train, cv=KFold(5, shuffle=True, random_state=7),
sample_weight=w_train, scoring=("deviance", "gini", "nll"), return_estimators=True,
)
session = EditorSession.from_model(
model, train_data=(X_train, y_train, w_train),
validation_data=(X_val, y_val, w_val), cv=cv,
)
session.widget()
return_estimators=Truekeeps each fold’s model, which the tab needs to draw every term’s relativities by fold. Without it the tab shows the fold scores and says how to get the curves.cv_data=(X, y, sample_weight)gives the rows the folds were drawn on. Without it the editor usestrain_datawhen its row count matches the folds.
The tab shows:
a header naming the folds, the splitter, the rows and where the result came from;
Performance across folds: each score’s mean, with one dot per fold;
Folds: each fold’s train and test rows, scores, EDF, fit time and whether it converged;
Relativities across folds: every term, least stable first, with a search box. fold gap is the mean distance of a fold’s curve from the fold average, and min r the lowest correlation of a fold with it.
Each relativity chart draws the levels in the model’s order. The fit curve (and the edited curve, once you edit) is exactly the curve the Editor tab draws for the term, value for value. Each fold’s curve is moved by a constant factor so its exposure-weighted mean log matches the fit’s, so folds compare on shape; fold gap and min r do not depend on that level. Hover over or focus a fold in the chart’s legend to pick it out.
Two buttons run jobs in the background, each with a Cancel button while it runs:
Run CV on current model refits the folds the result came from, with your hand edits put back as you set them, and it waits while changes are waiting for Refit. Its scores are shown beside the supplied ones, and its fold curves replace the supplied curves. A hand-edited term is marked held: it is the same curve on every fold.
Final fit on all rows uses the train and validation rows and leaves the test rows out, when there are any. It puts your hand edits back too. Its result appears on the Final Fit tab, with a line saying whether the refit converged, and Export offers it as Final fit model.
Run CV scores the folds with whichever of deviance, Gini and NLL the supplied result scored, or
with all three when it scored none of them. It fits each fold with the method the result records:
fit, unless you passed fit_mode="fit_reml" to cross_validate. It also passes the
warm_start and fit_kwargs you gave cross_validate. Its scores then differ from the supplied
ones only by your changes. Final fit uses the method the current model was fitted
with. Both jobs estimate what the opened model declares they estimate: a
selection_penalty="auto", smoothing that a fit_reml fit estimates, or a negative binomial
theta="auto" is chosen again on each fold’s rows and on the Final fit’s rows, after a Refit too.
A job whose model changed while it ran is not kept; run it again.
Both run in the background, so you can keep working. A pill beside the tabs shows how far a job has
got on every tab, and how it ended; click it to open the job’s tab. While Run CV runs, each fold’s
scores land on the cards and in the fold table as it finishes. When the folds split the rows, as
K-fold does, the Held out column shows the piece of the book each fold scored, and Rounds
shows how much smoothing search a fit_reml fold took, which is usually why one fold is slower.
The Diagnose tab answers whether each fit converged, whether its numbers can be used and what to try if not, from what the fits recorded, so opening it refits nothing. It opens on the first fit that did not converge, and one line above the table names every such fit; each name selects it.
Fits: one row per fit, led by its verdict. All rows is the model you are editing, fitted on every training row; each fold is fitted on its training part. A row’s verdict is one of: converged; converged with a looser stop (the numbers are usable, the smoothing was not checked to the strictest standard); did not converge, with the reason it stopped; or no smoothing search, because you set the smoothing. A fit that did not converge carries a cross and the words, not only a colour, and its fitted numbers, standard errors and degrees of freedom should not be relied on until it is refitted as the tab’s What to try says. A SuperLSS fit also names the smoothing search that made it, for example Quick smoothing updates, then Newton steps to an optimum. A fold that took at least twice the middle fold’s rounds, and at least ten, is marked slow, here and in the fold table, whose mark opens that fold in this tab.
Search path: how much REML score the fit in view gained in each smoothing round, beside the other fits. A search that settled ends at the bottom; one that stopped while still gaining ends higher, and its last point is crossed.
What the fit reports: a SuperLSS’s
diagnose()findings. Those that bear on the numbers show first; those about how the search went are folded under About the search. A SuperGLM has none.Smoothing by term: every fit’s effective degrees of freedom (EDF, how flexible a term is) side by side. A shaded cell means the fit left the term at the simplest shape its penalty allows, a straight line for most splines, or smoothed it away; a dot means the fit records that it reached the largest smoothing allowed.
Rows that cost the most: for a fold, the held-out rows its own fit predicted worst; for All rows, the training rows the fit predicted worst, which it was fitted on, so a fold’s held-out rows are the fairer test.
Where the time went: a SuperLSS’s work profile, folded until opened, without the phases that took under five milliseconds.
When every fit had its smoothing set, the tab says so once and shows only each term’s flexibility.
Folds come from Run CV, or from a supplied result with return_estimators=True.
A SuperLSS model works the same way: pass cross_validate(model, X_train, y_train, cv=folds, fit_mode="fit_reml", return_estimators=True) as cv=, with no scoring= argument. Its folds are
scored by log score, CRPS, Gini and actual over expected; a family with neither a closed-form CRPS
nor a distribution function has no CRPS, and its Validation and Final Fit tabs leave that column
out. Its offset is a dict by parameter, and its fold curves are listed under Mean and then
CV (Overdispersion for a negative binomial, Dispersion for a Tweedie), the least stable
first in each. Every curve on this tab is drawn as the Editor tab draws it, by its link (see
Which models open, and what a curve shows), and
the two tabs agree: the heading names the parameter and what the curve shows, for example
Area · CV · relativity of the CV (relativity of σ for a log-normal, relativity of the
overdispersion for a negative binomial, relativity of the dispersion for a Tweedie), and on
those four families higher always means more variation. The parameters and their labels are in
What the editor calls each parameter.
See also
Check a distributional fit.
Run CV is disabled, with the reason on hover, when it cannot use the rows:
cv_datahas a different row count from the data the folds were drawn on.train_datastands in forcv_dataand has a different row count.The rows are not the ones the folds were drawn on: the columns the model reads, or
y, the weights or the offsets, differ in type, row order or values, and a pandas frame and a polars one of the same values differ too. Columns the model does not read are not checked. Pass theX,y,sample_weightandoffsetyou gavecross_validate.The result’s data fingerprint was made by an earlier development build of superglm, or by another version, so its rows cannot be checked. Run
cross_validateagain.A column the model reads could not be fingerprinted: it holds objects whose text is not their value, or values that cannot be hashed. Convert those values to text or numbers and run
cross_validateagain.
A result from an older superglm version records no fingerprint of its data, so only the row count
is checked. An older result records no fit method either, so Run CV fits each fold the way the current
model was fitted. The tab says so in both cases. A result from before cross_validate took
warm_start and fit_kwargs was fitted without them, and Run CV replays it the same way. The older cv_report= argument of EditorSession.from_model
still works: its report is shown on the Validation tab.
Explain Risks (SuperLSS)#
A SuperLSS session has an Explain tab. It reads the model for single risks. It draws log-normal (mean form), gamma, negative binomial and Tweedie models; for other families it says so in place of the plots. Each row at the top is a risk: a value for every feature, starting at the reference risk, which has every number at its training median and every level at its most frequent. Every offset is at zero.
The plus button adds a risk, a training row drawn at random, up to eight. A risk keeps its letter and colour until it is removed.
Select a risk by its letter, or by working in its row. On the selected row, the icons take the values of another training row drawn at random, put the risk back at the reference risk, add a copy of it to change one value and compare, or remove it.
The plots show each risk’s whole predicted distribution: how likely each amount is, and the chance of an amount above each value, down to 1 in 10,000. The selected risk is filled. The line is the one the distribution panel uses: its box takes a number alone, and a press or a drag on the plots moves it.
The table has a row per risk: mean, median, the 90th, 99th and 99.5th percentiles, the chance above the line, and the CV. A line at one of those percentiles adds no second column, and a line written as 1 in N heads its column 1 in N. Two risks are followed by the ratio of the second to the first.
The walk explains the selected risk. It starts at risk A, or at the reference risk when risk A is selected, and has a row per feature that differs: the multiplier that feature alone puts on the mean and on the CV. The start times every row is the end. Where the model has interactions, what the features add only together is a row of its own. A risk that differs from its start in nothing gets one line saying so in place of the rows.
After an edit, one risk is read beside the original model’s distribution for it, and a row of the walk that the edit moved says what it was.
The tab fits one screen on a 16:9 window and in a notebook cell with a few risks. Each risk adds a row, so with more the page scrolls, and the plots keep a height that stays readable. At eight risks the plus button and the copy icon are off. A number outside the range of the training rows is accepted and its box turns orange: the model has no data there and extrapolates.
A Tweedie model has a chance of no claim. The table gives it for each risk; the upper plot covers the amounts above zero as a density given a claim, so every curve has an area of one, and the lower plot is the chance for the whole policy, so it starts at the chance of a claim. Its walk covers the mean and the dispersion, because the power is one constant for the model.
A negative binomial model has counts, not amounts: the plot is a bar per number of claims for each risk, for one unit of exposure, on a scale that keeps the rare counts in view, and the table reads the mean, the chance of no claim and of one, two and three or more, and the overdispersion. For a log-normal, the CV’s multipliers in the walk act on σ, the standard deviation of the log amount. The labels are in What the editor calls each parameter.
Keyboard Shortcuts#
Use Tab to reach application tabs, the feature list, the chart toolbar, the SVG action palette, and the inspector.
Use arrow keys inside tab lists, the mode switch and the join toggle; Home and End jump to the first and last item.
Use Enter or Space to activate a focused control.
Use Escape to close the current popover, Help drawer, inspector drawer, or dialog.
Use Ctrl/Cmd+Z to undo and Ctrl/Cmd+Shift+Z or Ctrl+Y to redo an edit, a waiting change or a step.
Press K to choose the Knots tool. With a knot selected, the arrow keys nudge it, ten steps at a time with Shift; Delete removes it and Escape clears the selection.
Press R to refit the waiting changes.
Pointer editing remains the primary high-density curve workflow. Full per-point keyboard editing and an alternate editable data table are separate future accessibility enhancements.