# neurostatx.cli.LogisticRegression

*module*

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/cli/LogisticRegression.py#L1-L1)

## neurostatx.cli.LogisticRegression.app

*attribute* · *module attribute*

```python
app = App(default_parameter=Parameter(negative=()))
```

Cyclopts application for the LogisticRegression command-line tool.

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/cli/LogisticRegression.py#L27-L27)

## neurostatx.cli.LogisticRegression.LogisticRegression

*function*

```python
def LogisticRegression(in_graph: Annotated[str, Parameter(show_default=False, group='Essential Files Options')], out_folder: Annotated[str, Parameter(show_default=False, group='Essential Files Options')], attributes: Annotated[List[str], Parameter(group='Model Parameters', show_default=False)], covariates: Annotated[List[str], Parameter(group='Model Parameters', show_default=True)] = None, weight: Annotated[str, Parameter(group='Model Parameters', show_default=True)] = 'membership', splits: Annotated[int, Parameter(group='Model Parameters', show_default=True)] = 10, test_size: Annotated[float, Parameter(group='Model Parameters', show_default=True)] = 0.2, cs: Annotated[int, Parameter(group='Model Parameters', show_default=True)] = 10, max_iter: Annotated[int, Parameter(group='Model Parameters', show_default=True)] = 1000, penalty: Annotated[Penalty, Parameter(group='Model Parameters', show_default=True, show_choices=True)] = Penalty.l2, solver: Annotated[Solver, Parameter(group='Model Parameters', show_default=True, show_choices=True)] = Solver.lbfgs, permutations: Annotated[int, Parameter(group='Model Parameters', show_default=True)] = 1000, scoring: Annotated[ScoringMethod, Parameter(group='Model Parameters', show_default=True)] = ScoringMethod.r2, processes: Annotated[int, Parameter(group='Model Parameters', show_default=True)] = 1, plot_distributions: Annotated[bool, Parameter(show_default=True, group='Visualization Options')] = False, verbose: Annotated[bool, Parameter(-v, --verbose, group='Optional parameters')] = False, save_parameters: Annotated[bool, Parameter(-s, --save_parameters, group='Optional parameters')] = False, overwrite: Annotated[bool, Parameter(-f, --overwrite, group='Optional parameters')] = False)
```

Fit logistic regression of graph edges against node attributes.

LogisticRegression uses edge weights as predictors and node attributes as
the response. It cross-validates on a training set, tests on held-out
data, then runs permutation testing for statistical significance. It writes
coefficients, statistics, and plots of attribute and edge-weight
distributions and of the coefficients.

> **Notes**
>
> **Preprocessing**
> 
> Data are scaled to unit variance and zero mean. Edge weights are
> log-transformed; for now this assumes the weights are membership values
> from a fuzzy clustering analysis.
> 
> **Node attributes**
> 
> The script takes a single .gml graph file, fetches node attributes from it,
> and fits the model on those attributes and the edge weights. At least one
> attribute is required. To attach attributes to nodes, see
> [AddNodesAttributes][neurostatx.cli.AddNodesAttributes.AddNodesAttributes].
> 
> **Scoring**
> 
> Permutation testing assesses whether the model is statistically
> significant. The p-value uses area under the curve (AUC) by default; other
> scores are listed in the scikit-learn scoring documentation [1]. The
> single-tailed p-value is:
> 
>     p-value = ∑(score_perm >= score) / (nb_permutations)
> 
> **Coefficient significance**
> 
> Coefficient p-values are also computed from the permutation distribution
> by comparing model coefficients to permuted coefficients. The two-tailed
> p-value is:
> 
>     p-value = ∑(abs(coef_perm) >= abs(coef)) / (nb_permutations)

> **References**
>
> [1] [scikit-learn scoring
> parameter](https://scikit-learn.org/stable/modules/model_evaluation.html#scoring-parameter)

**Parameters**

- `in_graph` (`str`) — Graph file containing the data for the model.
- `out_folder` (`str`) — Output folder.
- `attributes` (`List[str]`) — Attribute names to include in the model. Must be present in the graph file. At least one attribute is required.
- `covariates` (`List[str]`) (default: `None`) — Covariates to include in the model. Must be present in the graph file. Defaults to None.
- `weight` (`str`) (default: `'membership'`) — Edge weight to use for the model. Defaults to ``membership``.
- `splits` (`int`) (default: `10`) — Number of splits to use for the cross-validation. Defaults to 10.
- `test_size` (`float`) (default: `0.2`) — Size of the testing set. Must be between 0 and 1. Defaults to 0.2.
- `cs` (`int`) (default: `10`) — Inverse of regularization strength. Smaller values specify stronger regularization. Defaults to 10.
- `max_iter` (`int`) (default: `1000`) — Maximum number of iterations for the solver. Defaults to 1000.
- `penalty` (`Penalty`) (default: `Penalty.l2`) — Regularization penalty to use for the LogisticRegression model. Defaults to l2.
- `solver` (`Solver`) (default: `Solver.lbfgs`) — Solver to use for the LogisticRegression model. Defaults to lbfgs.
- `permutations` (`int`) (default: `1000`) — Number of permutations to use for the permutation testing. Defaults to 1000.
- `scoring` (`ScoringMethod`) (default: `ScoringMethod.r2`) — Scoring method to use for the permutation testing. Defaults to r2.
- `processes` (`int`) (default: `1`) — Number of processes to use for the cross-validation. Defaults to 1.
- `plot_distributions` (`bool`) (default: `False`) — If true, will plot the distributions of the edges' weights. Defaults to False.
- `verbose` (`bool`) (default: `False`) — If true, produce verbose output. Defaults to False.
- `save_parameters` (`bool`) (default: `False`) — If true, will save input parameters to .txt file. Defaults to False.
- `overwrite` (`bool`) (default: `False`) — If true, force overwriting of existing output files. Defaults to False.

**Examples**

```bash
LogisticRegression --in-graph graph.gexf --out-folder output_folder -v
-s
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/cli/LogisticRegression.py#L31-L413)
