SpaceX Falcon 9 first‑stage landing prediction

IBM Data Science capstone, January 2023

Python, pandas, NumPy, SQL, Folium, Plotly Dash, scikit-learn

Code

At a glance

  • What: a course exercise in predicting whether a Falcon 9 rocket's first stage will land. SpaceX lands and reuses that stage, which largely explains its lower prices, so the prediction could help a company bidding against SpaceX estimate what a launch costs.
  • My part: I collected the launch data in the course's notebooks, writing the steps that request it, keep only Falcon 9 launches and fill in missing values. For the later steps I used files the course prepared: 90 launches for the charts and models, and separate files for the SQL queries, the map and the dashboard. It was an individual capstone.
  • Result: all four models predicted 15 of 18 test launches correctly, against 12 for simply guessing that every first stage lands; I chose logistic regression as the simplest.

The question

Will a Falcon 9 first stage land? The course brief gave the reason it matters: SpaceX advertised launches at 62 million dollars while other providers charged upward of 165 million, largely because it lands and reuses the first stage.

Data and method

I collected launch records from SpaceX's public launch data service (an application programming interface, or API), using the course's helper code to turn its ID numbers into real values. I also scraped the Wikipedia list of Falcon 9 launches with BeautifulSoup. For the later steps the course supplied prepared files, including one of 90 Falcon 9 launches for the charts and models. I merged eight kinds of landing result into landed or not (60 of 90 landed). I then explored the data with charts and structured query language (SQL) queries, mapped the launch sites with Folium and built a Plotly Dash dashboard.

Landing success rate by year: zero from 2010 to 2013, over 80 percent in 2019 and 2020.

Results

I compared four standard prediction models (logistic regression, a support vector machine, a decision tree and k-nearest neighbours), each tuned with a grid search. On the 18 launches held back for testing, all four got 15 right, against 12 for simply guessing that every first stage lands. Their cross-validation scores were too close to separate, so I chose the simplest, logistic regression. It predicted all 12 landings correctly, but it also predicted a landing for 3 of the 6 launches that did not land.

Test results for the chosen model: every landing caught, 3 of the 6 failures caught.

Dashboard and map

Share of successful launches by site. The dashboard exercise came with its own file of 56 launches, not the 90 used for the models. The Florida pad KSC LC-39A had 10 of the 24 successes and the highest success rate, 10 of 13 launches.
Map of the United States with launch markers grouped in California and in Florida. (open the full-size image)
Launch sites on the Folium map, in California and Florida.

What I would do next

With only 18 test launches the models could not be told apart, so I would test them on more launches, including ones flown after this data was collected.