elphick.sklearn_viz.features.principal_components.PrincipalComponents
- class elphick.sklearn_viz.features.principal_components.PrincipalComponents(x, color=None)[source]
- __init__(x, color=None)[source]
- Parameters:
x (
DataFrame
) – X values to transform and plot.color (
Optional
[Series
]) – the optional series by which to color the markers
Methods
__init__
(x[, color])- type x:
DataFrame
add_loading_vectors
(fig, loadings)- rtype:
Figure
plot_explained_variance
([standardised, title])Plot the cumulative explained variance by principal component.
plot_loading_vectors
([standardised, ...])plot the loading vectors.
plot_principal_components
([plot_3d, ...])Create the pca plot
plot_scatter_matrix
([original_features, ...])Plot a scatter matrix
Attributes
data
- plot_explained_variance(standardised=False, title=None)[source]
Plot the cumulative explained variance by principal component.
- Parameters:
standardised (
bool
) – If True, plot the standardised PCA, where vectors are transformed to zero mean and unit variance.title (
Optional
[str
]) – Optional plot title
- Return type:
Figure
Returns:
- plot_loading_vectors(standardised=False, by_color=False, title=None)[source]
plot the loading vectors.
- Parameters:
standardised (
bool
) – If True, plot the standardised PCA, where vectors are transformed to zero mean and unit variance. by_color: If True, plot the loading vectors by color group.title (
Optional
[str
]) – Optional plot title
- Return type:
Figure
- Returns:
a plotly GraphObjects.Figure
- plot_principal_components(plot_3d=False, loading_vectors=True, standardised=False, title=None)[source]
Create the pca plot
- Parameters:
plot_3d (
bool
) – If True plot the top 3 principal components in 3D, otherwise the top 2 in 2D.loading_vectors (
bool
) – If True and plot_type is ‘2D’|’3D’ loading vectors will be displayed.standardised (
bool
) – If True, plot the standardised PCA, where vectors are transformed to zero mean and unit variance.title (
Optional
[str
]) – Optional plot title
- Loading vectors are implemented manually rather than with annotations (lines with arrows),
the problem is described well here: https://community.plotly.com/t/set-pca-loadings-aka-arrows-in-a-3d-scatter-plot/72905
- Return type:
Figure
- Returns:
a plotly GraphObjects.Figure
- plot_scatter_matrix(original_features=False, standardised=False, title=None)[source]
Plot a scatter matrix
- Parameters:
original_features (
bool
) – If True, plot the original features, otherwise plot the principal components.standardised (
bool
) – If True, plot the standardised PCA, where vectors are transformed to zero mean and unit variance.title (
Optional
[str
]) – Optional plot title
- Return type:
Figure
Returns: