Our Blog

Latest News

Progress: Radial Velocity: Using Machine Learning to Detect Exoplanets: A Step-by-Step Guide

This code is for a machine learning model that is trained to predict the radial velocity of exoplanets based on their wavelength. Radial velocity is the measure of the speed at which an object is moving away from or towards an observer. It is often used to detect exoplanets, which are planets that orbit stars outside of our solar system.

Exoplanets can be difficult to detect because they are very far away and relatively small compared to their host stars. One way to detect exoplanets is to look for changes in the radial velocity of the host star caused by the gravitational pull of the exoplanet. When an exoplanet orbits a star, it causes the star to move slightly towards and away from the observer, causing a periodic change in its radial velocity.

The machine learning model in this code is trained using data on the wavelengths and radial velocities of exoplanets. The model is then used to predict the radial velocities of new exoplanets based on their wavelengths. By comparing the predicted radial velocities to the actual values, it is possible to determine whether an exoplanet is present and estimate its characteristics, such as its mass and orbital period.

Overall, the possibility of discovering exoplanets using this machine learning model will depend on the quality and quantity of the data used to train the model, as well as the accuracy of the predictions made by the model. If the model is trained on a large and diverse dataset of exoplanet wavelengths and radial velocities, and is able to make accurate predictions, it may be possible to use the model to detect and characterize exoplanets with a high degree of confidence.

import csv
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import periodogram, find_peaks
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestRegressor

def process_exoplanet_data(data_file):
    # Read in the CSV file containing the exoplanet data
    with open(data_file, 'r') as f:
        reader = csv.reader(f)
        headers = next(reader)
        data = list(reader)

    # Convert the data to a NumPy array
    data = np.array(data).astype(float)

    # Extract the wavelength, intensity, and radial velocity columns
    X = data[:, headers.index('wavelength')]
    y = data[:, headers.index('radial_velocity')]

    # Split the data into training and test sets
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

    # Reshape the training data
    X_train = X_train[:, np.newaxis]
    y_train = y_train[:, np.newaxis]

    # Train a random forest regressor on the training data
    model = RandomForestRegressor(n_estimators=100)
    model.fit(X_train, y_train)

    # Evaluate the model on the test data
    y_pred = model.predict(X_test)
    score = model.score(X_test, y_test)
    print(f'Test score: {score:.2f}')

    # Create a scatter plot of the test data and the predictions
    plt.scatter(X_test, y_test, label='True')
    plt.scatter(X_test, y_pred, label='Predicted')
    plt.xlabel('Wavelength (nm)')
    plt.ylabel('Radial Velocity (km/s)')
    plt.legend()
    plt.show()

# Test the function with the exoplanet data file
process_exoplanet_data('exoplanet_data.csv')
Progress: Using Machine Learning to Identify Asteroids Suitable for Mining
Exoplanet Discovery and Characterization Using Radial Velocity Data