# Regression

Regression algorithms.

The attribute `values_` assigns a value to each node of the graph.

## Diffusion

class sknetwork.regression.Diffusion(n_iter: int = 3, damping_factor: Optional[float] = None)[source]

Regression by diffusion along the edges (heat equation).

Parameters
• n_iter (int) – Number of steps of the diffusion in discrete time (must be positive).

• damping_factor (float (optional)) – Damping factor (default value = 1).

Variables
• values_ (np.ndarray) – Value of each node (= temperature).

• values_row_ (np.ndarray) – Values of rows, for bipartite graphs.

• values_col_ (np.ndarray) – Values of columns, for bipartite graphs.

Example

```>>> from sknetwork.data import house
>>> diffusion = Diffusion(n_iter=2)
>>> seeds = {0: 1, 2: 0}
>>> np.round(values, 2)
array([0.58, 0.56, 0.38, 0.58, 0.42])
```

References

Chung, F. (2007). The heat kernel as the pagerank of a graph. Proceedings of the National Academy of Sciences.

fit(input_matrix: Union[scipy.sparse.csr.csr_matrix, numpy.ndarray], seeds: Optional[Union[numpy.ndarray, dict]] = None, seeds_row: Optional[Union[numpy.ndarray, dict]] = None, seeds_col: Optional[Union[numpy.ndarray, dict]] = None, init: Optional[float] = None) [source]

Compute the diffusion (temperatures at equilibrium).

Parameters

• seeds – Temperatures of seed nodes in initial state (dictionary or vector). Negative temperatures ignored.

• seeds_row – Temperatures of rows and columns for bipartite graphs. Negative temperatures ignored.

• seeds_col – Temperatures of rows and columns for bipartite graphs. Negative temperatures ignored.

• init – Temperature of non-seed nodes in initial state. If `None`, use the average temperature of seed nodes (default).

Returns

self

Return type

`Diffusion`

fit_transform(*args, **kwargs) numpy.ndarray

Fit algorithm to data and return the scores. Same parameters as the `fit` method.

Returns

values – Values.

Return type

np.ndarray

## Dirichlet

class sknetwork.regression.Dirichlet(n_iter: int = 10, damping_factor: Optional[float] = None, verbose: bool = False)[source]

Regression by the Dirichlet problem (heat diffusion with boundary constraints).

Parameters
• n_iter (int) – If positive, number of steps of the diffusion in discrete time. Otherwise, solve the Dirichlet problem by the bi-conjugate gradient stabilized method.

• damping_factor (float (optional)) – Damping factor (default value = 1).

• verbose (bool) – Verbose mode.

Variables
• values_ (np.ndarray) – Value of each node (= temperature).

• values_row_ (np.ndarray) – Values of rows, for bipartite graphs.

• values_col_ (np.ndarray) – Values of columns, for bipartite graphs.

Example

```>>> from sknetwork.regression import Dirichlet
>>> from sknetwork.data import house
>>> dirichlet = Dirichlet()
>>> seeds = {0: 1, 2: 0}
>>> np.round(values, 2)
array([1.  , 0.54, 0.  , 0.31, 0.62])
```

References

Chung, F. (2007). The heat kernel as the pagerank of a graph. Proceedings of the National Academy of Sciences.

fit(input_matrix: Union[scipy.sparse.csr.csr_matrix, numpy.ndarray], seeds: Optional[Union[numpy.ndarray, dict]] = None, seeds_row: Optional[Union[numpy.ndarray, dict]] = None, seeds_col: Optional[Union[numpy.ndarray, dict]] = None, init: Optional[float] = None) [source]

Compute the solution to the Dirichlet problem (temperatures at equilibrium).

Parameters

• seeds – Temperatures of seed nodes (dictionary or vector). Negative temperatures ignored.

• seeds_row – Temperatures of rows and columns for bipartite graphs. Negative temperatures ignored.

• seeds_col – Temperatures of rows and columns for bipartite graphs. Negative temperatures ignored.

• init – Temperature of non-seed nodes in initial state. If `None`, use the average temperature of seed nodes (default).

Returns

self

Return type

`Dirichlet`

fit_transform(*args, **kwargs) numpy.ndarray

Fit algorithm to data and return the scores. Same parameters as the `fit` method.

Returns

values – Values.

Return type

np.ndarray