corrGraph package
Submodules
corrGraph.corrGraph module
- class corrGraph.corrGraph.Config[source]
Bases:
objectConfiguration class for setting default parameters for the correlation graph visualization.
- AXIS_CONFIG = {'showgrid': False, 'showline': False, 'showticklabels': False, 'title': '', 'zeroline': False}
- DEFAULT_EDGE_WIDTH = 0.01
- DEFAULT_NODE_SIZE = 0.5
- EDGE_WIDTH_SCALE = 1
- FIGURE_SIZE = '800px'
- LAYOUT_CONFIG = {'annotations': [{'showarrow': False, 'text': 'Visualization of the correlation graph', 'x': 0.005, 'xref': 'paper', 'y': -0.002, 'yref': 'paper'}], 'height': 800, 'hovermode': 'closest', 'margin': {'b': 20, 'l': 5, 'r': 5, 't': 40}, 'showlegend': False, 'title': '<br>Correlation Graph', 'titlefont_size': 16, 'width': 800, 'xaxis': {'showgrid': False, 'showline': False, 'showticklabels': False, 'title': '', 'zeroline': False}, 'yaxis': {'showgrid': False, 'showline': False, 'showticklabels': False, 'title': '', 'zeroline': False}}
- NEGATIVE_COLOR = 'orange'
- NODE_SIZE_SCALE = 20
- POSITIVE_COLOR = 'blue'
- class corrGraph.corrGraph.CorrGraph(corr_matrix: DataFrame, threshold: float = 0.5, use_correlations_as_weights: bool = True)[source]
Bases:
objectClass for creating and visualizing a correlation graph from a correlation matrix.
- get_centrality(centrality_type: str = 'degree') Dict[str, float][source]
Calculate and return the centrality of each node in the graph based on the specified centrality type.
- Parameters:
centrality_type – A string to specify the type of centrality measure (‘degree’, ‘betweenness’, ‘closeness’, ‘eigenvector’).
- Returns:
A dictionary where keys are node names and values are their centrality measures.
- Raises:
ValueError – If an invalid centrality type is provided.
- get_graph() Graph[source]
Get the created graph.
- Returns:
A networkx Graph object representing the correlation graph.
- update_node_weights(weights: Dict[str, float]) None[source]
Update the weights of the nodes in the graph.
- Parameters:
weights – A dictionary where keys are node names and values are the weights to be assigned.
- Raises:
ValueError – If a node is not found in the graph.
TypeError – If a weight is not numeric.
- visualize_graph(visualization_type: str = 'plotly', node_weight_is_size: bool = True, edge_weight_is_size: bool = True, use_as_notebook: bool = True) None[source]
Visualize the graph using either Plotly or PyVis based on the visualization_type argument.
- Parameters:
visualization_type – A string to decide which visualization library to use (‘plotly’ or ‘pyvis’).
node_weight_is_size – A boolean to decide if node weights should determine node sizes.
edge_weight_is_size – A boolean to decide if edge weights should determine edge widths.
use_as_notebook – A boolean to decide if the visualization should be displayed in a Jupyter notebook (only for PyVis).
- visualize_graph_with_plotly(node_weight_is_size: bool = True, edge_weight_is_size: bool = True) None[source]
Visualize the graph using Plotly.
- Parameters:
node_weight_is_size – A boolean to decide if node weights should determine node sizes.
edge_weight_is_size – A boolean to decide if edge weights should determine edge widths.
- visualize_graph_with_pyvis(node_weight_is_size: bool = True, edge_weight_is_size: bool = True, use_as_notebook=True) None[source]
Visualize the graph using PyVis.
- Parameters:
node_weight_is_size – A boolean to decide if node weights should determine node sizes.
edge_weight_is_size – A boolean to decide if edge weights should determine edge widths.
use_as_notebook – A boolean to decide if the visualization should be displayed in a Jupyter notebook.