watex.analysis.total_variance_ratio#
- watex.analysis.total_variance_ratio(X, view=False)[source]#
Compute the total variance ratio.
Is the ratio of an eigenvalues \(\lambda_j\), as simply the fraction of and eigen value, \(\lambda_j\) and the total sum of the eigen values as:
\[\text{explained_variance_ratio}= \frac{\lambda_j}{\sum{j=1}^{d} \lambda_j}\]Using numpy cumsum function, we can then calculate the cumulative sum of explained variance which can be plot if plot is set to
Truevia matplotlib set function.- Parameters:
X (Nd-array, shape(M, N)) β Array of training set with M examples and N-features
view (bool, default {'False'}) β give an overview of the total explained variance.
- Returns:
cum_var_exp β Cumulative sum of variance total explained.
- Return type:
array-like
Examples
>>> from watex.analysis import total_variance_ratio >>> # Use the X value in the example of `extract_pca` function >>> cum_var = total_variance_ratio(X, view=True) >>> cum_var ... array([0.26091916, 0.44042728, 0.57625294, 0.69786032, 0.80479823, 0.89379712, 0.97474381, 1. ])