{"id":19213548,"url":"https://github.com/aryanyadav-dev/celestial-spectroscopy","last_synced_at":"2026-04-11T22:02:45.354Z","repository":{"id":261447197,"uuid":"884340274","full_name":"aryanyadav-dev/celestial-spectroscopy","owner":"aryanyadav-dev","description":"Developed a Deep learning model using TensorFlow and Keras to classify synthetic spectral data from celestial objects, including stars and galaxies. Utilizing a Convolutional Neural Network (CNN), the model analyzes spectroscopic features and achieves high accuracy in predicting object classifications.","archived":false,"fork":false,"pushed_at":"2024-11-17T17:52:56.000Z","size":313410,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-04-06T19:35:11.228Z","etag":null,"topics":["cnn","keras","matplotlib","python","sckit-learn","tensorflow"],"latest_commit_sha":null,"homepage":"","language":"Python","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/aryanyadav-dev.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":"2024-11-06T15:18:53.000Z","updated_at":"2024-12-03T09:44:14.000Z","dependencies_parsed_at":"2025-06-02T10:54:08.722Z","dependency_job_id":null,"html_url":"https://github.com/aryanyadav-dev/celestial-spectroscopy","commit_stats":null,"previous_names":["aryanyadav-dev/celestial-spectroscopy"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/aryanyadav-dev/celestial-spectroscopy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aryanyadav-dev%2Fcelestial-spectroscopy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aryanyadav-dev%2Fcelestial-spectroscopy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aryanyadav-dev%2Fcelestial-spectroscopy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aryanyadav-dev%2Fcelestial-spectroscopy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aryanyadav-dev","download_url":"https://codeload.github.com/aryanyadav-dev/celestial-spectroscopy/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aryanyadav-dev%2Fcelestial-spectroscopy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31696743,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-11T21:17:31.016Z","status":"ssl_error","status_checked_at":"2026-04-11T21:17:24.556Z","response_time":54,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["cnn","keras","matplotlib","python","sckit-learn","tensorflow"],"created_at":"2024-11-09T14:06:16.707Z","updated_at":"2026-04-11T22:02:45.322Z","avatar_url":"https://github.com/aryanyadav-dev.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Spectral Classifier\n\nThis project is designed to classify spectral data using a convolutional neural network (CNN) implemented in TensorFlow/Keras. The model takes spectral data (typically flux vs. wavelength) as input and classifies it into predefined categories (e.g., stars and galaxies). The classifier works with 1D spectral data and leverages deep learning techniques to perform the classification.\n\n## Features\n\n- **Spectral Data Preprocessing**: The code preprocesses spectral data by normalizing it and reshaping it for the CNN input.\n- **Convolutional Neural Network**: The classifier is built using 1D convolutional layers (Conv1D), pooling layers, dense layers, and dropout layers to prevent overfitting.\n- **Model Training and Visualization**: The training process includes callbacks like EarlyStopping, ModelCheckpoint, and TensorBoard, and the training history (accuracy and loss) is visualized.\n- **Evaluation**: The model evaluates the performance on test data using metrics such as precision, recall, F1 score, and provides a confusion matrix and classification report.\n- **Sample Spectra Visualization**: The classifier also allows plotting sample spectra with their corresponding labels.\n- **Sentiment Analysis**: Helps to understand whether it a star or a galaxy by positive or neutral sentiment.\n\n## Installation\n\n### Prerequisites\n\nBefore you begin, ensure you have the following installed:\n\n- Python 3.x\n- TensorFlow (preferably v2.x)\n- NumPy\n- Matplotlib\n- Scikit-learn\n\nYou can install the necessary Python packages using `pip`:\n\n```bash\npip install tensorflow numpy matplotlib scikit-learn\n```\n\n## Usage\n\n### 1. Prepare Your Data\n\nYou need spectral data and corresponding labels. The data should be in the form of a 2D array (`spectra`), where each row represents one sample and each column represents a wavelength point. The labels should be a list of category names (e.g., `['star', 'galaxy']`).\n\n### 2. Create and Train the Model\n\n```python\n# Import necessary libraries\nfrom spectral_classifier import SpectralClassifier\n\n# Example spectral data and labels\nspectra = ...  # Your spectral data as a 2D numpy array (samples x features)\nlabels = ...   # Your labels as a list of strings (e.g., ['star', 'galaxy'])\n\n# Initialize the classifier\ninput_shape = (spectra.shape[1], 1)  # Shape of the input data (number of features, 1 channel)\nnum_classes = len(set(labels))  # Number of unique classes in the dataset\nclassifier = SpectralClassifier(input_shape=input_shape, num_classes=num_classes)\n\n# Preprocess data\nX_train, X_test, y_train, y_test, label_encoder = classifier.preprocess_data(spectra, labels)\n\n# Train the model and visualize the results\nclassifier.train_and_visualize(X_train, y_train, X_test, y_test, epochs=20)\n```\n\n### 3. Evaluate the Model\n\nOnce the model is trained, you can evaluate its performance on the test data:\n\n```python\n# Evaluate the model\ncm, cr, precision, recall, f1 = classifier.evaluate_model(X_test, y_test)\n```\n\nThis will output a confusion matrix, classification report, and key evaluation metrics (precision, recall, F1 score).\n\n### 4. Visualize Sample Spectra\n\nYou can also visualize some sample spectra with their corresponding labels:\n\n```python\n# Plot sample spectra\nclassifier.plot_sample_spectra(spectra, labels, num_samples=5)\n```\n\n## Methods\n\n### `SpectralClassifier` Class\n\n- **`__init__(input_shape, num_classes, regression=False)`**: Initializes the classifier with the input shape and number of classes.\n- **`_build_model()`**: Builds the CNN model with Conv1D layers and appropriate activation and dropout layers.\n- **`preprocess_data(spectra, labels)`**: Normalizes the spectra, reshapes it for Conv1D input, encodes labels, and splits the data into training and testing sets.\n- **`train_and_visualize(X_train, y_train, X_val, y_val, epochs=20)`**: Trains the model and visualizes the training and validation accuracy and loss.\n- **`_plot_training_history(history)`**: Plots the training and validation accuracy/loss.\n- **`evaluate_model(X_test, y_test)`**: Evaluates the model on the test set and prints the confusion matrix, classification report, and other evaluation metrics (precision, recall, F1).\n- **`plot_sample_spectra(spectra, labels, num_samples=5)`**: Visualizes sample spectra with their corresponding labels.\n\n## How to Run the File\n\n1. **Prepare the Data**: Ensure you have your spectral data and corresponding labels in the correct format.\n   - Spectral data should be a 2D numpy array where each row corresponds to a sample, and each column represents the spectral features (e.g., wavelength points).\n   - Labels should be a list of strings corresponding to the category of each sample (e.g., `['star', 'galaxy']`).\n\n2. **Run the Classifier**:\n   - Clone or download the project files.\n   - In your Python script, import the `SpectralClassifier` class.\n   - Load your spectral data and labels, then preprocess them using the `preprocess_data()` method.\n   - Train the model using the `train_and_visualize()` method.\n   - Evaluate the model using `evaluate_model()`.\n   - Optionally, visualize sample spectra using `plot_sample_spectra()`.\n\n3. **Run the Script**:\n   - Save your Python script, ensuring it is in the same directory as `spectral_classifier.py` or adjust the import accordingly.\n   - Run the script from the terminal or your Python IDE:\n   ```bash\n   python your_script.py\n   ```\n\nThe script will train the model, visualize the progress, and evaluate its performance.\n\n## Example Output\n\nDuring training, you will see the following outputs:\n\n- **Training and Validation Accuracy/Loss**: Plotted graphs showing how the model's accuracy and loss improve over epochs.\n- **Confusion Matrix**: A heatmap of the confusion matrix showing the classification performance.\n- **Classification Report**: Detailed performance metrics (precision, recall, F1 score) for each class.\n\n### Example of Classification Report:\n```\n              precision    recall  f1-score   support\n\n         Star       0.95      0.92      0.93       100\n       Galaxy       0.89      0.93      0.91       100\n\n    accuracy                           0.92       200\n   macro avg       0.92      0.92      0.92       200\nweighted avg       0.92      0.92      0.92       200\n```\n\n### Example of Confusion Matrix:\n```\nConfusion Matrix:\n[[92  8]\n [ 7 93]]\n```\n\n## Notes\n\n- Ensure that your spectral data is properly formatted and normalized.\n- The `train_and_visualize()` method includes early stopping and model checkpointing to avoid overfitting and save the best model during training.\n- The model is designed for classification tasks, but you can modify it for regression by setting the `regression=True` flag during initialization.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faryanyadav-dev%2Fcelestial-spectroscopy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faryanyadav-dev%2Fcelestial-spectroscopy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faryanyadav-dev%2Fcelestial-spectroscopy/lists"}