This project focuses on classifying stellar objects (stars, galaxies, and quasars) based on astronomical features extracted from observational data. Utilizing machine learning techniques, specifically RandomForest and Support Vector Machines (SVM), this project aims to build robust models for accurate stellar classification.
The project uses a dataset containing various features of celestial objects. The target variable is class, which categorizes objects into 'GALAXY', 'QSO' (Quasar), or 'STAR'.
The dataset includes the following features, which are crucial for classification:
Categorical Features:
class: The type of stellar object (GALAXY, QSO, STAR). This is the target variable.
Numerical Features:
alpha: Right Ascension angle (J2000)delta: Declination angle (J2000)u,g,r,i,z: Photometric magnitudes in different filters (ultraviolet, green, red, infrared, and another infrared band respectively). These represent the brightness of the object in various wavelengths.redshift: A measure of how much the light from the object has been stretched due to the expansion of the universe.run_id: Run number used to identify the specific scan.field_id: Field number used to identify the specific field.spec_obj_id: Unique ID used for optical spectroscopic surveys.mjd: Modified Julian Date, used to specify the time of observation.fiber_id: Optical fiber ID that took the spectroscopic measurement.
The project follows a standard machine learning pipeline:
The dataset is loaded using pandas, and initial checks are performed to understand its structure, identify missing values, and analyze the distribution of features.
- Handling Categorical Features: The
classvariable, being the target, is used directly. Other categorical features are handled as part of the pipeline. - Feature Scaling: Numerical features are scaled using
StandardScalerto ensure that features with larger values do not dominate the learning process. - Column Transformer: A
ColumnTransformeris used to apply different preprocessing steps to numerical and categorical features within a single pipeline.
Two powerful classification algorithms are employed:
-
RandomForestClassifier: An ensemble learning method that builds multiple decision trees and merges their predictions.
- Hyperparameter Tuning:
GridSearchCVwithStratifiedKFoldcross-validation is used to find the optimal hyperparameters for the RandomForest model, includingn_estimators,max_depth, andmin_samples_split.
- Hyperparameter Tuning:
-
LinearSVC (Support Vector Machine): A linear classifier that finds the optimal hyperplane to separate classes.
- Hyperparameter Tuning:
GridSearchCVis used to tune theCparameter (regularization parameter) for the LinearSVC model.
- Hyperparameter Tuning:
Both models are evaluated based on their accuracy and confusion matrices to understand their performance in classifying different stellar object types.
For the best-performing SVM model (after GridSearchCV), the coefficients are analyzed to determine the most important features in predicting the type of stellar object. This provides insights into which astronomical measurements are most indicative of an object's classification.
The project will present:
- The performance metrics (e.g., accuracy) of the optimized RandomForest and SVM models.
- Confusion matrices for both models, illustrating their classification strengths and weaknesses across different stellar classes.
- A visualization of the most important features as determined by the SVM model, highlighting which observational parameters contribute most significantly to the classification.
To run this notebook, you'll need the following Python libraries:
pandasnumpymatplotlibseabornscikit-learnscipy
You can install them using pip:
pip install pandas numpy matplotlib seaborn scikit-learn scipy