Estimated time needed: 70 minutes
In this assignment, we will predict if the Falcon 9 first stage will land successfully. SpaceX advertises Falcon 9 rocket launches on its website with a cost of 62 million dollars; other providers cost upward of 165 million dollars each, much of the savings is due to the fact that SpaceX can reuse the first stage.
In this lab, you will perform Exploratory Data Analysis and Feature Engineering.
Falcon 9 first stage will land successfully
Several examples of an unsuccessful landing are shown here:
Most unsuccessful landings are planned. Space X performs a controlled landing in the oceans.
Perform exploratory Data Analysis and Feature Engineering using
Pandas
and
Matplotlib
We will import the following libraries the lab
# andas is a software library written for the Python programming language for data manipulation and analysis.
import pandas as pd
#NumPy is a library for the Python programming language, adding support for large, multi-dimensional arrays and matrices, along with a large collection of high-level mathematical functions to operate on these arrays
import numpy as np
# Matplotlib is a plotting library for python and pyplot gives us a MatLab like plotting framework. We will use this in our plotter function to plot data.
import matplotlib.pyplot as plt
#Seaborn is a Python data visualization library based on matplotlib. It provides a high-level interface for drawing attractive and informative statistical graphics
import seaborn as sns
First, let's read the SpaceX dataset into a Pandas dataframe and print its summary
# df=pd.read_csv("https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBM-DS0321EN-SkillsNetwork/datasets/dataset_part_2.csv")
df=pd.read_csv("data/IBM-DS0321EN-SkillsNetwork/datasets/dataset_part_2.csv")
# If you were unable to complete the previous lab correctly you can uncomment and load this csv
# df = pd.read_csv('https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-DS0701EN-SkillsNetwork/api/dataset_part_2.csv')
df.head(5)
First, let's try to see how the
FlightNumber
(indicating the continuous launch attempts.) and
Payload
variables would affect the launch outcome.
We can plot out the
FlightNumber
vs.
PayloadMass
and overlay the outcome of the launch. We see that as the flight number increases, the first stage is more likely to land successfully. The payload mass is also important; it seems the more massive the payload, the less likely the first stage will return.
sns.catplot(y="PayloadMass", x="FlightNumber", hue="Class", data=df, aspect = 5)
plt.xlabel("Flight Number",fontsize=20)
plt.ylabel("Pay load Mass (kg)",fontsize=20)
plt.show()
We see that different launch sites have different success rates.
CCAFS LC-40
, has a success rate of 60 %, while
KSC LC-39A
and
VAFB SLC 4E
has a success rate of 77%.
Next, let's drill down to each site visualize its detailed launch records.
Use the function
catplot
to plot
FlightNumber
vs
LaunchSite
, set the parameter
x
parameter to
FlightNumber
,set the
y
to
Launch Site
and set the parameter
hue
to
'class'
# Plot a scatter point chart with x axis to be Flight Number and y axis to be the launch site, and hue to be the class value
sns.catplot(y="LaunchSite", x="FlightNumber", hue="Class", data=df)
plt.xlabel("Flight Number")
plt.ylabel("Launch Site")
plt.show()
Now try to explain the patterns you found in the Flight Number vs. Launch Site scatter point plots.
We also want to observe if there is any relationship between launch sites and their payload mass.
# Plot a scatter point chart with x axis to be Pay Load Mass (kg) and y axis to be the launch site, and hue to be the class value
sns.catplot(y="LaunchSite", x="PayloadMass", hue="Class", data=df)
plt.xlabel("Pay Load Mass (kg)")
plt.ylabel("Launch Site")
plt.show()
Now if you observe Payload Vs. Launch Site scatter point chart you will find for the VAFB-SLC launchsite there are no rockets launched for heavypayload mass(greater than 10000).
Next, we want to visually check if there are any relationship between success rate and orbit type.
Let's create a
bar chart
for the sucess rate of each orbit
# HINT use groupby method on Orbit column and get the mean of Class column
df.groupby("Orbit")["Class"].mean().plot(kind='bar', xlabel="Orbit", ylabel="Success Rate", title="Success rate per orbit type")
plt.show()
Analyze the ploted bar chart try to find which orbits have high sucess rate.
For each orbit, we want to see if there is any relationship between FlightNumber and Orbit type.
# Plot a scatter point chart with x axis to be FlightNumber and y axis to be the Orbit, and hue to be the class value
sns.catplot(y="Orbit", x="FlightNumber", hue="Class", data=df)
plt.xlabel("Flight Number")
plt.ylabel("Orbit")
plt.show()
You should see that in the LEO orbit the Success appears related to the number of flights; on the other hand, there seems to be no relationship between flight number when in GTO orbit.
Similarly, we can plot the Payload vs. Orbit scatter point charts to reveal the relationship between Payload and Orbit type
# Plot a scatter point chart with x axis to be Payload and y axis to be the Orbit, and hue to be the class value
sns.catplot(y="Orbit", x="PayloadMass", hue="Class", data=df)
plt.xlabel("Pay Load Mass (kg)")
plt.ylabel("Orbit")
plt.show()
With heavy payloads the successful landing or positive landing rate are more for Polar,LEO and ISS.
However for GTO we cannot distinguish this well as both positive landing rate and negative landing(unsuccessful mission) are both there here.
You can plot a line chart with x axis to be
Year
and y axis to be average success rate, to get the average launch success trend.
The function will help you get the year from the date:
# A function to Extract years from the date
year=[]
def Extract_year(date):
for i in df["Date"]:
year.append(i.split("-")[0])
return year
# Plot a line chart with x axis to be the extracted year and y axis to be the success rate
df.assign(year=lambda x:[i.split("-")[0] for i in x["Date"]]).groupby("year")["Class"].mean().plot(xlabel="Year", ylabel="Success Rate", title="Success rate by year")
plt.show()
you can observe that the sucess rate since 2013 kept increasing till 2020
By now, you should obtain some preliminary insights about how each important variable would affect the success rate, we will select the features that will be used in success prediction in the future module.
features = df[['FlightNumber', 'PayloadMass', 'Orbit', 'LaunchSite', 'Flights', 'GridFins', 'Reused', 'Legs', 'LandingPad', 'Block', 'ReusedCount', 'Serial']]
features.head()
Use the function
get_dummies
and
features
dataframe to apply OneHotEncoder to the column
Orbits
,
LaunchSite
,
LandingPad
, and
Serial
. Assign the value to the variable
features_one_hot
, display the results using the method head. Your result dataframe must include all features including the encoded ones.
# HINT: Use get_dummies() function on the categorical columns
features_one_hot = pd.get_dummies(features, columns=["Orbit", "LaunchSite", "LandingPad", "Serial"])
features_one_hot.head()
float64
¶
Now that our
features_one_hot
dataframe only contains numbers cast the entire dataframe to variable type
float64
# HINT: use astype function
features_one_hot = features_one_hot.astype('float64')
features_one_hot.head()
We can now export it to a CSV for the next section,but to make the answers consistent, in the next lab we will provide data in a pre-selected date range.
features_one_hot.to_csv('dataset_part\_3.csv', index=False)
Joseph Santarcangelo has a PhD in Electrical Engineering, his research focused on using machine learning, signal processing, and computer vision to determine how videos impact human cognition. Joseph has been working for IBM since he completed his PhD.
Nayef Abou Tayoun is a Data Scientist at IBM and pursuing a Master of Management in Artificial intelligence degree at Queen's University.
Date (YYYY-MM-DD) | Version | Changed By | Change Description |
---|---|---|---|
2021-10-12 | 1.1 | Lakshmi Holla | Modified markdown |
2020-09-20 | 1.0 | Joseph | Modified Multiple Areas |
2020-11-10 | 1.1 | Nayef | updating the input data |
Copyright © 2020 IBM Corporation. All rights reserved.