spacr.qt.screens.profiler¶
Workflow inputs and outputs¶
Prediction Profiler¶
Inspect how a fitted model responds as an input feature changes; predictions do not establish causal effects.
Open: Regression → Prediction Profiler.
Inputs and outputs below include conditional alternatives. The guidance and handoff notes say which route applies.
Inputs
Fitted feature classifier — The fitted tabular classifier and its recorded feature list, training settings and validation results.
Outputs
Figures and table exports — The output location chosen by the tool; exports describe the selected data and filters.
Prediction Profiler — interrogate a fitted model one input at a time.
A coefficient table says which terms matter. It does not say what the model would predict for a well like yours, and it certainly does not say what happens if this one gRNA’s fraction doubles while everything else stays put. That question — one input moving, the rest pinned where you chose — is what this screen answers.
inputs (ranked) ┌─────────────────────────────────┐
▸ grna[233460_1] +2.4 │ ______/ │
grna[239740_3] -1.8 │ _____/ │
grna[000000_2] +0.1 │ ___/ │
└─────────────────────────────────┘
held: grna[239740_3] ──●──── 0.31
grna[000000_2] ●────── 0.02
The left column is spacr.profiler.sensitivity() — every input ranked by
how far it actually moves the prediction, not by its coefficient, because a
large coefficient on an input that never varies moves nothing. That ranking
is what makes a three-thousand-term design usable: it tells you which input
to open the profiler on.
Nothing is re-fitted. The screen reads a coefficient table a regression
run already wrote and wraps it in spacr.profiler.FittedLinear, which
is reading the fit. A profiler that re-fits is showing a second model under
the first one’s name, and on a penalised backend with alpha='auto' it is
not even the same model. A caller that has a live fitted object can hand it
straight to ProfilerScreen.set_model() and skip the file entirely.
The link is named, not guessed. A coefficient table does not record which inverse link produced it, and applying the wrong one draws a plausible curve on the wrong scale. So the link is a control the user sets, it defaults to identity, and the axis label always says which one is in force.
Where there is no design, the assumption is stated. Without the original design matrix the observed range of each input is unknown, so the screen sweeps 0-1 — the range a per-gRNA fraction lives in — and says so in the status strip rather than implying it measured something.
Classes¶
Draws one |
|
Sweep one input of a fitted model; hold the rest. |
Functions¶
|
Map a profile onto pixel coordinates inside |
|
Factory the registry calls to build this screen. |
|
Add Prediction Profiler to the app registry. Idempotent. |
Module Contents¶
- class spacr.qt.screens.profiler.CurveCanvas(parent=None)[source]¶
Bases:
PySide6.QtWidgets.QWidgetDraws one
Profile.- Parameters:
parent – Qt parent.
Create the empty profile canvas.
- Parameters:
parent – parent widget, or
None.
- curve() spacr.profiler.Profile | None[source]¶
The profile currently drawn, or
None.
- class spacr.qt.screens.profiler.ProfilerScreen(parent=None, coefficients: str = '', model: Any = None, design: pandas.DataFrame | None = None, threaded: bool = True)[source]¶
Bases:
PySide6.QtWidgets.QWidgetSweep one input of a fitted model; hold the rest.
- Parameters:
parent – Qt parent.
coefficients – open straight onto this coefficient CSV.
model – use this already-fitted object instead of reading a file.
design – the design matrix, when the caller has it. Without one the screen sweeps
DEFAULT_RANGEand says so.threaded –
Falsecomputes inline, so a test drives the screen synchronously without the behaviour diverging.
- Variables:
last_error – text of the most recent failure,
""when the last operation worked.
Build the screen and arm its drop zone.
A model can arrive three ways and they are tried in order: an already-fitted model, a coefficients CSV to read one from, or nothing – in which case the screen says which file to choose.
- Parameters:
parent – parent widget, or
None.coefficients – a results CSV to load the model from.
model – an already-fitted model, which wins over
coefficients.design – the design matrix the model was fitted on.
threaded – profile on a worker thread. Set
Falsein tests so a profile finishes before it returns.
- closeEvent(event) None[source]¶
Drain the worker before the widget goes.
- Parameters:
event – the close event; passed to the base class after the worker threads are shut down.
- curve() spacr.profiler.Profile | None[source]¶
The profile currently drawn, or
None.
- design() pandas.DataFrame[source]¶
The design the sweeps run over — supplied or synthesized.
- load_coefficients(path: str) None[source]¶
Read a coefficient table and profile the model it describes.
- Parameters:
path – CSV file with
featureandcoefficientcolumns; read on a worker thread and rebuilt with the chosen link. An empty path only asks for a table.
- set_design(design: pandas.DataFrame | None) None[source]¶
Supply the design matrix, so the sweeps use observed ranges.
- Parameters:
design – the design matrix the model was fitted on, one column per input;
Noneor an empty frame falls back to a synthetic design. A loaded model is re-profiled at once.
- set_held(name: str, value: float) None[source]¶
Hold one input at
valueand redraw.- Parameters:
name – the input to hold; it must have a held-value slider or
KeyErroris raised.value – the value to hold it at, clamped to the slider’s range and snapped to its nearest step.
- set_model(model: Any, *, design: pandas.DataFrame | None = None) None[source]¶
Profile an already-fitted object, skipping the file entirely.
- Parameters:
model – a fitted object
spacr.profiler.predict()accepts (a statsmodels result, a scikit-learn estimator, anything withparamsorcoef_, or aFittedLinear);Nonereports that the model could not be read.
- spacr.qt.screens.profiler.curve_points(curve: spacr.profiler.Profile | None, width: int, height: int, *, margin: int = 36) List[Tuple[float, float]][source]¶
Map a profile onto pixel coordinates inside
widthxheight.Split out from the widget so the plot is testable without reading pixels back: the shape of the curve is a property of this function, and the
paintEventonly strokes what it returns.- Parameters:
curve – the profile to plot;
Noneor empty gives[].width – canvas width in pixels.
height – canvas height in pixels.
margin – gutter reserved for the axes.
- Returns:
(x, y)pairs, left to right, y measured downwards.