standard_scaler#

gammapy.utils.cluster.standard_scaler(features)[source]#

Compute standardized features by removing the mean and scaling to unit variance.

Calculated through:

\[f_\text{scaled} = \frac{f-\text{mean}(f)}{\text{std}(f)} .\]
Parameters:
featuresTable

Table containing the features.

Returns:
scaled_featuresTable

Table containing the scaled features (dimensionless).

Examples

Compute standardized features of a cluster observations based on their IRF quantities:

>>> from gammapy.data.utils import get_irfs_features
>>> from gammapy.data import DataStore
>>> from gammapy.utils.cluster import standard_scaler
>>> from astropy.coordinates import SkyCoord
>>> import astropy.units as u
>>> data_store = DataStore.from_dir("$GAMMAPY_DATA/hess-dl3-dr1/")
>>> obs_ids = data_store.obs_table["OBS_ID"][:3]
>>> obs = data_store.get_observations(obs_ids)
>>> position = SkyCoord(329.716 * u.deg, -30.225 * u.deg, frame="icrs")
>>> names = ["edisp-res", "psf-radius"]
>>> features_irfs = get_irfs_features(
...     obs,
...     energy_true="1 TeV",
...     position=position,
...     names=names
... )
>>> scaled_features_irfs = standard_scaler(features_irfs)
>>> print(scaled_features_irfs)
     edisp-res      obs_id      psf-radius
------------------- ------ --------------------
-0.1379190199428797  20136 -0.18046952655570045
 1.2878662980210884  20137   1.3049664466089965
-1.1499472780781963  20151  -1.1244969200533408