-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspacex_wrangling_week1_3.py
168 lines (101 loc) · 618 KB
/
spacex_wrangling_week1_3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# -*- coding: utf-8 -*-
"""SpaceX_Wrangling_week1_3.ipynb
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/13k6St_zDJlkki6Ft_S5K9xtf62tWUnye
# Data Wrangling
Lab 2: Data wrangling
In this lab, we will perform some Exploratory Data Analysis (EDA) to find some patterns in the data and determine what would be the label for training supervised models.
In the data set, there are several different cases where the booster did not land successfully. Sometimes a landing was attempted but failed due to an accident; for example, True Ocean means the mission outcome was successfully landed to a specific region of the ocean while False Ocean means the mission outcome was unsuccessfully landed to a specific region of the ocean. True RTLS means the mission outcome was successfully landed to a ground pad False RTLS means the mission outcome was unsuccessfully landed to a ground pad.True ASDS means the mission outcome was successfully landed on a drone ship False ASDS means the mission outcome was unsuccessfully landed on a drone ship.
In this lab we will mainly convert those outcomes into Training Labels with 1 means the booster successfully landed 0 means it was unsuccessful.
Perform exploratory Data Analysis and determine Training Labels
## Objectives
- Exploratory Data Analysis EDA
- Determine Training Labels
Import Libraries and Define Auxiliary Functions
We will import the following libraries.
"""
# Pandas 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
"""#Data Analysis"""
# Now, let's delve into the relationships between the columns and the data they contain.
# let's delve into the factors that contribute to successful and unsuccessful landings.
df = pd.read_csv("https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBM-DS0321EN-SkillsNetwork/datasets/dataset_part_2.csv")
df.head(5) #standard date #booster version is Falcon9 # Longitude # Latitude and finally we have a clean data
df.isnull().sum() #Let's take a quick look at the data to see how many values are missing.
len(df)*100
df.isnull().sum()/len(df)*100 #To determine the percentage of empty columns in our dataset.
df.dtypes #kind of type
df.info()
"""#TASK 1: Calculate the number of launches on each site
The data contains several Space X launch facilities: Cape Canaveral Space Launch Complex 40 VAFB SLC 4E , Vandenberg Air Force Base Space Launch Complex 4E (SLC-4E), Kennedy Space Center Launch Complex 39A KSC LC 39A .The location of each Launch Is placed in the column LaunchSite
Next, let's see the number of launches for each site.
Use the method value_counts() on the column LaunchSite to determine the number of launches on each site:
"""
# Apply value_counts() on column LaunchSite
df['LaunchSite'].value_counts()
"""* <b>LEO</b>: Low Earth orbit (LEO)is an Earth-centred orbit with an altitude of 2,000 km (1,200 mi) or less (approximately one-third of the radius of Earth),[1] or with at least 11.25 periods per day (an orbital period of 128 minutes or less) and an eccentricity less than 0.25.[2] Most of the manmade objects in outer space are in LEO <a href='https://en.wikipedia.org/wiki/Low_Earth_orbit'>[1]</a>.
* <b>VLEO</b>: Very Low Earth Orbits (VLEO) can be defined as the orbits with a mean altitude below 450 km. Operating in these orbits can provide a number of benefits to Earth observation spacecraft as the spacecraft operates closer to the observation<a href='https://www.researchgate.net/publication/271499606_Very_Low_Earth_Orbit_mission_concepts_for_Earth_Observation_Benefits_and_challenges'>[2]</a>.
* <b>GTO</b> A geosynchronous orbit is a high Earth orbit that allows satellites to match Earth's rotation. Located at 22,236 miles (35,786 kilometers) above Earth's equator, this position is a valuable spot for monitoring weather, communications and surveillance. Because the satellite orbits at the same speed that the Earth is turning, the satellite seems to stay in place over a single longitude, though it may drift north to south,” NASA wrote on its Earth Observatory website <a href="https://www.space.com/29222-geosynchronous-orbit.html" >[3] </a>.
* <b>SSO (or SO)</b>: It is a Sun-synchronous orbit also called a heliosynchronous orbit is a nearly polar orbit around a planet, in which the satellite passes over any given point of the planet's surface at the same local mean solar time <a href="https://en.wikipedia.org/wiki/Sun-synchronous_orbit">[4] <a>.
* <b>ES-L1 </b>:At the Lagrange points the gravitational forces of the two large bodies cancel out in such a way that a small object placed in orbit there is in equilibrium relative to the center of mass of the large bodies. L1 is one such point between the sun and the earth <a href="https://en.wikipedia.org/wiki/Lagrange_point#L1_point">[5]</a> .
* <b>HEO</b> A highly elliptical orbit, is an elliptic orbit with high eccentricity, usually referring to one around Earth <a href="https://en.wikipedia.org/wiki/Highly_elliptical_orbit">[6]</a>.
* <b> ISS </b> A modular space station (habitable artificial satellite) in low Earth orbit. It is a multinational collaborative project between five participating space agencies: NASA (United States), Roscosmos (Russia), JAXA (Japan), ESA (Europe), and CSA (Canada)<a href="https://en.wikipedia.org/wiki/International_Space_Station"> [7] </a>
* <b> MEO </b> Geocentric orbits ranging in altitude from 2,000 km (1,200 mi) to just below geosynchronous orbit at 35,786 kilometers (22,236 mi). Also known as an intermediate circular orbit. These are "most commonly at 20,200 kilometers (12,600 mi), or 20,650 kilometers (12,830 mi), with an orbital period of 12 hours <a href="https://en.wikipedia.org/wiki/List_of_orbits"> [8] </a>
* <b> HEO </b> Geocentric orbits above the altitude of geosynchronous orbit (35,786 km or 22,236 mi) <a href="https://en.wikipedia.org/wiki/List_of_orbits"> [9] </a>
* <b> GEO </b> It is a circular geosynchronous orbit 35,786 kilometres (22,236 miles) above Earth's equator and following the direction of Earth's rotation <a href="https://en.wikipedia.org/wiki/Geostationary_orbit"> [10] </a>
* <b> PO </b> It is one type of satellites in which a satellite passes above or nearly above both poles of the body being orbited (usually a planet such as the Earth <a href="https://en.wikipedia.org/wiki/Polar_orbit"> [11] </a>

some are shown in the following plot:
#TASK 2: Calculate the number and occurrence of each orbit
Use the method .value_counts() to determine the number and occurrence of each orbit in the column Orbit
"""
# Apply value_counts on Orbit column
df['Orbit'].value_counts()
"""#TASK 3: Calculate the number and occurence of mission outcome per orbit type
Use the method .value_counts() on the column Outcome to determine the number of landing_outcomes.Then assign it to a variable landing_outcomes.
"""
# landing_outcomes = values on Outcome column
landing_outcomes= df['Outcome'].value_counts()
landing_outcomes
"""True Ocean means the mission outcome was successfully landed to a specific region of the ocean while False Ocean means the mission outcome was unsuccessfully landed to a specific region of the ocean. True RTLS means the mission outcome was successfully landed to a ground pad False RTLS means the mission outcome was unsuccessfully landed to a ground pad.True ASDS means the mission outcome was successfully landed to a drone ship False ASDS means the mission outcome was unsuccessfully landed to a drone ship. None ASDS and None None these represent a failure to land."""
for i,outcome in enumerate(landing_outcomes.keys()): #This line of code instructs us to extract and display unique key-value pairs.
print(i,outcome)
bad_outcomes=set(landing_outcomes.keys()[[1,3,5,6,7]])
bad_outcomes #The ones that caused our landing to be unsuccessful are bad_outcomes(None None)
#This code snippet iterates through the landing_outcomes array and checks if each element is equal to (false) or (None None). If it is, the element is added to the bad_outcomes set.
# landing_class = 0 if bad_outcome
# landing_class = 1 otherwise
df_success = df[df["Class"]==1]
df_fai = df[df["Class"] !=1]
print(df_success['Outcome'].value_counts())
print(df_fai['Outcome'].value_counts())
"""#TASK 4: Create a landing outcome label from Outcome column
Using the Outcome, create a list where the element is zero if the corresponding row in Outcome is in the set bad_outcome; otherwise, it's one. Then assign it to the variable landing_class:
This variable will represent the classification variable that represents the outcome of each launch. If the value is zero, the first stage did not land successfully; one means the first stage landed Successfully
"""
outcome #If the event is in the bad_outcome list, meaning it is undesirable, 0 is appended to the results list.
#Otherwise, 1 is appended to the results list.
#The bad_outcome list contains undesirable events.
bad_outcomes=['False ASDS', 'False Ocean', 'False RTLS', 'None ASDS', 'None None']
landing_class=[]
for i in df['Outcome']:
if i in bad_outcomes:
landing_class.append(0)
else:
landing_class.append(1)
#Let's check if the landing_class list, which was previously empty, has been populated with any data.
print(landing_class)
df['Class']=landing_class #Now we're dropping landig_class into the class
df[['Class']].head(8)
#df_success = df[df["Class"]==1]
#df_fai = df[df["Class"] !=1]
#print(df_success['Outcome'].value_counts())
#print(df_fai['Outcome'].value_counts())
df.head(5)
"""We can use the following line of code to determine the success rate:"""
df["Class"].mean()
"""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."""
df.to_csv("dataset_part_2.csv", index=False)