cellrank.models.GAM¶
- class cellrank.models.GAM(adata, n_knots=6, spline_order=3, distribution='gamma', link='log', max_iter=2000, expectile=None, grid=None, spline_kwargs=mappingproxy({}), **kwargs)[source]¶
Fit Generalized Additive Models (GAMs) using
pygam.- Parameters:
adata (
AnnData) – Annotated data object.spline_order (
int) – Order of the splines, e.g., \(3\) for cubic splines.distribution (
Literal['normal','binomial','poisson','gamma','gaussian','inv_gauss']) – Name of the distribution. Available distributions can be found here.link (
Literal['identity','logit','inverse','log','inv_squared']) – Name of the link function. Available link functions can be found here.max_iter (
int) – Maximum number of iterations for optimization.expectile (
float|None) – Expectile forExpectileGAM. This forces the distribution to be'normal'and link function to'identity'. Must be in \((0, 1)\).grid (
str|Mapping[str,Any] |None) – Whether to perform a grid search. Keys correspond to a parameter names and values to range to be searched. If'default', use the default grid. IfNone, don’t perform a grid search.spline_kwargs (
Mapping[str,Any]) – Keyword arguments fors().
Attributes table¶
Annotated data object. |
|
Array of shape |
|
Underlying model. |
|
Whether the model is prepared for fitting. |
|
Number of cells in |
|
Filtered weights of shape |
|
Unfiltered weights of shape |
|
Filtered independent variables of shape |
|
Unfiltered independent variables of shape |
|
Filtered independent variables used when calculating default confidence interval, usually same as |
|
Independent variables of shape |
|
Filtered dependent variables of shape |
|
Unfiltered dependent variables of shape |
|
Filtered dependent variables used when calculating default confidence interval, usually same as |
|
Prediction values of shape |
Methods table¶
|
Calculate the confidence interval. |
|
Return a copy of self. |
|
Calculate the confidence interval, if the underlying |
|
Fit the model. |
|
Plot the smoothed gene expression. |
|
Run the prediction. |
|
Prepare the model to be ready for fitting. |
|
De-serialize self from a file. |
|
Serialize self to a file using |
Attributes¶
adata¶
- GAM.adata¶
Annotated data object.
conf_int¶
- GAM.conf_int¶
Array of shape
(n_samples, 2)containing the lower and upper bound of the confidence interval.
model¶
- GAM.model¶
Underlying model.
prepared¶
- GAM.prepared¶
Whether the model is prepared for fitting.
shape¶
signal¶
w¶
- GAM.w¶
Filtered weights of shape
(n_filtered_cells,)used for fitting.
w_all¶
- GAM.w_all¶
Unfiltered weights of shape
(n_cells,).
x¶
- GAM.x¶
Filtered independent variables of shape
(n_filtered_cells, 1)used for fitting.
x_all¶
- GAM.x_all¶
Unfiltered independent variables of shape
(n_cells, 1).
x_hat¶
x_test¶
- GAM.x_test¶
Independent variables of shape
(n_samples, 1)used for prediction.
y¶
- GAM.y¶
Filtered dependent variables of shape
(n_filtered_cells, 1)used for fitting.
y_all¶
- GAM.y_all¶
Unfiltered dependent variables of shape
(n_cells, 1).
y_hat¶
y_test¶
Methods¶
confidence_interval¶
copy¶
default_confidence_interval¶
- GAM.default_confidence_interval(x_test=None, **kwargs)¶
Calculate the confidence interval, if the underlying
modelhas no method for it.This formula is taken from [DeSalvo, 1970], eq. 5.
- Parameters:
- Return type:
- Returns:
: Returns self and updates the following fields:
Also updates the following fields:
fit¶
- GAM.fit(x=None, y=None, w=None, **kwargs)[source]¶
Fit the model.
- Parameters:
x (
ndarray|None) – Independent variables, array of shape(n_samples, 1). IfNone, usex.y (
ndarray|None) – Dependent variables, array of shape(n_samples, 1). IfNone, usey.w (
ndarray|None) – Optional weights ofx, array of shape(n_samples,). IfNone, usew.kwargs (
Any) – Keyword arguments for underlyingmodel’s fitting function.
- Return type:
- Returns:
: Fits the model and returns self.
plot¶
- GAM.plot(figsize=(8, 5), same_plot=False, hide_cells=False, perc=None, fate_prob_cmap=<matplotlib.colors.ListedColormap object>, cell_color=None, lineage_color='black', alpha=0.8, lineage_alpha=0.2, title=None, size=15, lw=2, cbar=True, margins=0.015, xlabel='pseudotime', ylabel='expression', conf_int=True, lineage_probability=False, lineage_probability_conf_int=False, lineage_probability_color=None, obs_legend_loc='best', dpi=None, fig=None, ax=None, return_fig=False, save=None, **kwargs)¶
Plot the smoothed gene expression.
- Parameters:
same_plot (
bool) – Whether to plot all trends in the same plot.hide_cells (
bool) – Whether to hide the cells.perc (
tuple[float,float]) – Percentile by which to clip the fate probabilities.fate_prob_cmap (
ListedColormap) – Colormap to use when coloring in the fate probabilities.cell_color (
str|None) – Key inobsorvar_namesused for coloring the cells.lineage_color (
str) – Color for the lineage.alpha (
float) – Alpha value in \([0, 1]\) for the transparency of cells.lineage_alpha (
float) – Alpha value in \([0, 1]\) for the transparency lineage confidence intervals.size (
int) – Size of the points.lw (
float) – Line width for the smoothed values.cbar (
bool) – Whether to show the colorbar.margins (
float) – Margins around the plot.xlabel (
str) – Label on the x-axis.ylabel (
str) – Label on the y-axis.conf_int (
bool) – Whether to show the confidence interval.lineage_probability (
bool) – Whether to show smoothed lineage probability as a dashed line. Note that this will require 1 additional model fit.lineage_probability_conf_int (
bool|float) – Whether to compute and show smoothed lineage probability confidence interval.lineage_probability_color (
str|None) – Color to use when plotting the smoothedlineage_probability. IfNone, it’s the same aslineage_color. Only used whenshow_lineage_probability = True.obs_legend_loc (
str|None) – Location of the legend whencell_colorcorresponds to a categorical variable.dpi (
int) – Dots per inch.save (
str|None) – Filename where to save the plot. IfNone, just shows the plots.
- Return type:
- Returns:
: Nothing, just plots the figure. Optionally saves it based on
save.
predict¶
prepare¶
- GAM.prepare(signal=<object object>, lineage=<object object>, time_key=<object object>, backward=False, time_range=None, data_key=<object object>, use_raw=<object object>, threshold=None, weight_threshold=(0.01, 0.01), filter_cells=None, n_test_points=200, *, gene=<object object>)¶
Prepare the model to be ready for fitting.
- Parameters:
The observation-aligned quantity to fit along the trajectory. Either a
Signal(Gene,ObsorObsm) or, as a shorthand, a gene name invar_names(equivalent toGene).Added in version 2.3.
lineage (
str|None) – Name of the lineage. IfNone, all weights will be set to \(1\).backward (
bool) – Direction of the process.time_range (
float|tuple[float,float] |None) –Specify start and end times:
Deprecated since version 2.4: Pass a
Signalviasignalinstead, e.g.Gene(name, layer=...)orObs(name).use_raw (
bool) –Deprecated since version 2.4: Pass
Gene(name, use_raw=True)viasignalinstead.Deprecated since version 2.4: Renamed to
signal, which also acceptsSignalobjects.threshold (
float|None) – Consider only cells with weights >thresholdwhen estimating the test endpoint. IfNone, use the median of the weights.weight_threshold (
float|tuple[float,float]) – Set all weights belowweight_thresholdtoweight_thresholdif afloat, or to the second value, if atuple.filter_cells (
float|None) – Filter out all cells with expression values lower than this threshold.n_test_points (
int) – Number of test points. IfNone, use the original points based onthreshold.
- Return type:
- Returns:
: Nothing, just updates the following fields:
x- Filtered independent variables of shape(n_filtered_cells, 1)used for fitting.y- Filtered dependent variables of shape(n_filtered_cells, 1)used for fitting.w- Filtered weights of shape(n_filtered_cells,)used for fitting.x_all- Unfiltered independent variables of shape(n_cells, 1).y_all- Unfiltered dependent variables of shape(n_cells, 1).w_all- Unfiltered weights of shape(n_cells,).x_test- Independent variables of shape(n_samples, 1)used for prediction.prepared- Whether the model is prepared for fitting.
read¶
- static GAM.read(fname, adata=None, copy=False)¶
De-serialize self from a file.
- Parameters:
- Return type:
IOMixin- Returns:
: The de-serialized object.