{"id":26432678,"url":"https://github.com/ratna-babu/graph-coloring-using-gcn","last_synced_at":"2025-09-11T22:31:54.765Z","repository":{"id":274302942,"uuid":"922504934","full_name":"Ratna-Babu/Graph-Coloring-using-GCN","owner":"Ratna-Babu","description":"This project is about graph coloring using Neural Networks (NNs) applied to graph-structured data, specifically the Cora citation network dataset. ","archived":false,"fork":false,"pushed_at":"2025-01-26T13:17:27.000Z","size":413,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-16T01:42:56.470Z","etag":null,"topics":["gcn","graphcoloring","neural-network"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Ratna-Babu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-01-26T11:56:45.000Z","updated_at":"2025-04-22T09:17:16.000Z","dependencies_parsed_at":null,"dependency_job_id":"0889ba41-3207-4758-9f45-6e5132f45168","html_url":"https://github.com/Ratna-Babu/Graph-Coloring-using-GCN","commit_stats":null,"previous_names":["ratna-babu/graph-coloring-using-neural-network"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Ratna-Babu/Graph-Coloring-using-GCN","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ratna-Babu%2FGraph-Coloring-using-GCN","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ratna-Babu%2FGraph-Coloring-using-GCN/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ratna-Babu%2FGraph-Coloring-using-GCN/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ratna-Babu%2FGraph-Coloring-using-GCN/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ratna-Babu","download_url":"https://codeload.github.com/Ratna-Babu/Graph-Coloring-using-GCN/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ratna-Babu%2FGraph-Coloring-using-GCN/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274717636,"owners_count":25336940,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-11T02:00:13.660Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gcn","graphcoloring","neural-network"],"created_at":"2025-03-18T06:19:40.241Z","updated_at":"2025-09-11T22:31:54.750Z","avatar_url":"https://github.com/Ratna-Babu.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Graph Coloring using Graph Convolutional Network (GCN)\n\nThis project is about graph coloring using Neural Networks (NNs) applied to graph-structured data, specifically the Cora citation network dataset. The project implements a Graph Convolutional Network (GCN) model to predict node classes (colors) for graph coloring, with an emphasis on hyperparameter tuning, early stopping, and learning rate scheduling.\n\n### Key Components of the Project:\n\n1.  **Graph Data**:\n\n    -   The project uses the **Cora dataset**, which is a citation network consisting of 2708 scientific papers (nodes) that are linked by citation relationships (edges).\n    -   The nodes have feature vectors representing the content of the papers, and the edges represent citation links between them.\n    -   Each node (paper) belongs to one of the predefined classes (or categories), and the task is to predict these classes using the graph structure and node features.\n2.  **Model Architecture**:\n\n    -   **GCN (Graph Convolutional Network)**:\n        -   The core of the model is a two-layer GCN, implemented using `GCNConv` layers from PyTorch Geometric. These layers learn node representations based on both the node features and the graph structure (edges).\n        -   The output layer uses **log-softmax** activation, which is appropriate for multi-class classification (coloring nodes in different categories).\n    -   **GraphSAGE (Graph Sample and Aggregation)**:\n        -   A second model variant, **GraphSAGE**, is implemented for comparison. GraphSAGE is a more advanced method for learning node embeddings by aggregating information from a node's neighbors.\n3.  **Training Loop**:\n\n    -   The training procedure involves optimizing the model using **cross-entropy loss** for multi-class classification and the **Adam optimizer**.\n    -   The training loop includes functionality for **early stopping** to avoid overfitting. This is controlled by the `EarlyStopping` class, which monitors the validation accuracy and stops the training if the accuracy doesn't improve for a specified number of epochs.\n    -   The **learning rate scheduler** (`ReduceLROnPlateau`) adjusts the learning rate based on the loss to prevent overshooting and improve convergence.\n4.  **Hyperparameter Tuning**:\n\n    -   The project uses **grid search** to experiment with different hyperparameter configurations such as learning rate, hidden dimension size, dropout rate, and the number of epochs.\n    -   The grid search is done via the `ParameterGrid` from `sklearn.model_selection` to evaluate the model on different combinations of parameters and identify the best set of hyperparameters.\n5.  **Evaluation**:\n\n    -   After training, the model's performance is evaluated using accuracy on a test set (nodes that were not part of the training).\n    -   The performance is also evaluated using **classification report** and **confusion matrix**, providing detailed metrics like precision, recall, and F1-score for each class (color).\n6.  **Graph Visualization**:\n\n    -   The final output is a visualization of the **Cora citation graph**, where nodes are colored according to the predicted class (color) for each paper.\n    -   The graph is visualized using **NetworkX** and **matplotlib**. The nodes are positioned using a **spring layout**, which is a force-directed layout algorithm that spaces nodes based on their connectivity in the graph.\n    -   The `pred` variable holds the predicted class (color) for each node, and these colors are used in the plot.\n7.  **Model Saving and Loading**:\n\n    -   The trained model is saved to a file using `torch.save()`, allowing it to be loaded later for inference or further training using `model.load_state_dict()`.\n\n### High-Level Project Workflow:\n\n1.  **Data Loading**: Load the Cora dataset and inspect its structure, including the number of nodes, edges, and features.\n2.  **Model Definition**: Define the GCN and GraphSAGE models using PyTorch and PyTorch Geometric.\n3.  **Training and Hyperparameter Tuning**: Train the model with different hyperparameter configurations using grid search, learning rate scheduling, and early stopping.\n4.  **Evaluation**: After training, evaluate the model's performance using accuracy, classification metrics, and confusion matrix.\n5.  **Visualization**: Visualize the graph with node colors based on the predicted classes.\n\n### GitHub Project Explanation:\n\nThis repository likely contains the code for the above steps, and each script might be structured as follows:\n\n-   **Data loading and exploration**: Load and inspect the Cora dataset.\n-   **Model definition**: Define the GCN and GraphSAGE models and other necessary components (e.g., optimizer, loss function, etc.).\n-   **Training**: Implement the training loop, validation, early stopping, and learning rate scheduling.\n-   **Evaluation**: Compute and print the evaluation metrics and confusion matrix.\n-   **Visualization**: Generate a visualization of the graph, showing the node classifications (colors).\n-   **Hyperparameter search**: Implement grid search for hyperparameter optimization.\n\nThis project is a good example of applying deep learning models to graph-structured data and can be extended to other graph coloring problems or graph classification tasks.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fratna-babu%2Fgraph-coloring-using-gcn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fratna-babu%2Fgraph-coloring-using-gcn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fratna-babu%2Fgraph-coloring-using-gcn/lists"}