-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
245 lines (123 loc) · 5.14 KB
/
main.py
File metadata and controls
245 lines (123 loc) · 5.14 KB
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#!/usr/bin/env python
# coding: utf-8
# ## Observations and Insights
#
# In[142]:
# Dependencies and Setup
import matplotlib.pyplot as plt
import pandas as pd
import scipy.stats as st
import numpy as np
# Study data files
mouse_metadata_path = "data/Mouse_metadata.csv"
study_results_path = "data/Study_results.csv"
# Read the mouse data and the study results
mouse_metadata = pd.read_csv(mouse_metadata_path)
study_results = pd.read_csv(study_results_path)
# Combine the data into a single dataset
dataset = pd.merge(mouse_metadata, study_results, on ="Mouse ID" , how = "outer")
dataset.head()
# In[143]:
# Checking the number of mice in the DataFrame.
mice = dataset["Mouse ID"]
len(mice)
# In[144]:
# Getting the duplicate mice by ID number that shows up for Mouse ID and Timepoint.
# In[145]:
# Create a clean DataFrame by dropping the duplicate mouse by its ID.
miceu = dataset["Mouse ID"].unique()
# In[146]:
# Checking the number of mice in the clean DataFrame.
len(miceu)
# ## Summary Statistics
# In[147]:
# Generate a summary statistics table of mean, median, variance, standard deviation,
# and SEM of the tumor volume for each regimen
regimen = dataset.groupby(["Drug Regimen"])
rmean = regimen["Tumor Volume (mm3)"].mean()
rmedian = regimen["Tumor Volume (mm3)"].median()
rvar = regimen["Tumor Volume (mm3)"].var()
rsd = regimen["Tumor Volume (mm3)"].std()
ssem = regimen["Tumor Volume (mm3)"].sem()
rcount = regimen["Mouse ID"].count()
summary_df = pd.DataFrame ({"Mean": rmean, "Median": rmedian, "Variance": rvar, "Standard Deviation": rsd, "SEM": ssem})
# In[148]:
rcount
# ## Bar Plots
# In[149]:
# Generate a bar plot showing the number of mice per time point for
# each treatment throughout the course of the study using pandas.
rcount = regimen["Mouse ID"].count()
rcount.plot(kind="bar", figsize=(10,5))
plt.title("Data Points Visual")
plt.xlabel("Drug Regimen")
plt.ylabel("Data Points")
plt.show()
plt.tight_layout()
# In[150]:
# Generate a bar plot showing the number of mice per time point
# for each treatment throughout the course of the study using pyplot.
drugs = [230, 178, 178, 188, 186, 181, 161, 228, 181, 182]
x_axis = np.arange(len(rcount))
plt.bar(x_axis, drugs, color='b', alpha=1, align='center')
tick_locations = [value for value in x_axis]
plt.xticks(tick_locations, ['Capomulin', 'Ceftamin', 'Infubinol', 'Ketapril', 'Naftisol', 'Placebo', 'Propriva', 'Ramicane', 'Stelasyn', 'Zoniferol'], rotation='vertical')
plt.xlim(-0.75, len(x_axis)-0.25)
plt.ylim(0, max(drugs)+10)
plt.title("Data Points Visual")
plt.xlabel("Drug Regimen")
plt.ylabel("Data Points")
# ## Pie Plots
# In[151]:
# Generate a pie plot showing the distribution of female versus male mice using panda
gender = pd.DataFrame(dataset.groupby(["Sex"]).count()).reset_index()
gender = gender [["Sex","Mouse ID"]]
gender = gender.rename(columns={"Mouse ID": "Count"})
plt.figure(figsize=(10,6))
pie = plt.subplot(121, aspect='equal')
gender.plot(kind='pie', y = "Count", ax=pie, autopct='%1.1f%%',
startangle=150, shadow=False, labels=gender['Sex'], legend = False, fontsize=15)
# In[152]:
# Generate a pie plot showing the distribution of female versus male mice using pyplot
genders = ["Female","Male"]
percent = [49.4,50.6]
colors = ['orange', 'blue']
plt.pie(percent, labels=genders, colors=colors, autopct="%1.1f%%", shadow=True, startangle=140)
# ## Quartiles, Outliers and Boxplots
# In[153]:
# Calculate the final tumor volume of each mouse across four of the most promising
# treatment regimens.
# Calculate the IQR and quantitatively determine if there are any potential outliers.
top4 = dataset[dataset["Drug Regimen"].isin(["Capomulin", "Ramicane", "Infubinol", "Ceftamin"])]
top4a = top4.sort_values(["Timepoint"], ascending=True)
top4b = top4a[["Drug Regimen", "Mouse ID", "Timepoint", "Tumor Volume (mm3)"]]
# In[167]:
# Generate a box plot of the final tumor volume of each mouse across four regimens of interest
# ## Line and Scatter Plots
# In[178]:
# Generate a line plot of time point versus tumor volume for a mouse treated with Capomulin
Tumor = dataset[dataset["Mouse ID"].isin(["s185"])]
Tumord = Tumor[["Mouse ID", "Timepoint", "Tumor Volume (mm3)"]]
Index = Tumord.reset_index()
line = Index[["Mouse ID", "Timepoint", "Tumor Volume (mm3)"]]
plot = line.plot.line()
# In[164]:
# Generate a scatter plot of mouse weight versus average tumor volume for the Capomulin regimen
sp = dataset[dataset["Drug Regimen"].isin(["Capomulin"])]
sp_df = top4a[["Mouse ID","Weight (g)", "Tumor Volume (mm3)"]]
sp_plot = sp.reset_index()
sp_sorted = sp_plot.sort_values(["Weight (g)"], ascending=True)
group_w = sp_plot.groupby("Weight (g)")["Tumor Volume (mm3)"].mean()
sp_group = pd.DataFrame(group_w).reset_index()
sp_plot = sp_group.plot(kind='scatter', x='Weight (g)', y='Tumor Volume (mm3)', grid = True, figsize= (6,6))
# In[ ]:
# ## Correlation and Regression
# In[157]:
# Calculate the correlation coefficient and linear regression model
# for mouse weight and average tumor volume for the Capomulin regimen
# In[177]:
sp['Weight (g)'].corr(sp['Tumor Volume (mm3)'])
# In[ ]:
# In[ ]:
# In[ ]:
# In[ ]: