-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTitanuc.py
206 lines (88 loc) · 2.14 KB
/
Titanuc.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
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
#!/usr/bin/env python
# coding: utf-8
# # Importing Modules
# In[10]:
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings('ignore')
get_ipython().run_line_magic('matplotlib', 'inline')
# # Loading Dataset
# In[44]:
train = pd.read_csv(r'C:\Users\Aditya Singh\Downloads\titanic.csv')
df = train
train.head()
# In[5]:
## Statistics of dataset
train.describe()
# In[6]:
## datatype info
train.info()
# # Exploratory Data Analysis
# In[11]:
## categorical attributes
sns.countplot(train['survived'])
# In[12]:
sns.countplot(train['pclass'])
# In[13]:
sns.countplot(train['sex'])
# In[14]:
sns.countplot(train['sibsp'])
# In[15]:
sns.countplot(train['parch'])
# In[18]:
sns.countplot(train['embarked'])
# In[22]:
## numerical attributes
sns.distplot(train['age'])
# In[23]:
sns.distplot(train['fare'])
# In[27]:
class_fare = train.pivot_table(index='pclass',values='fare')
class_fare.plot(kind='bar')
plt.xlabel('Pclass')
plt.xlabel('AvgFare')
# In[28]:
class_fare = train.pivot_table(index='pclass',values='fare',aggfunc=np.sum)
class_fare.plot(kind='bar')
plt.xlabel('Pclass')
plt.xlabel('TotalFare')
# In[60]:
sns.barplot(data=train,x='pclass',y='fare',hue='survived')
# In[45]:
#finding null
train.isnull().sum()-1#subtracted one to adjust the index
# In[42]:
train[train['pclass'].isnull()]
# In[46]:
#removing column
df = df.drop(columns=['cabin','boat','body','home.dest'],axis=1)
# In[47]:
df.head()
# In[49]:
#filling null for numerical
df['age'] = df['age'].fillna(df['age'].mean())
df['fare'] = df['fare'].fillna(df['fare'].mean())
# In[53]:
df['embarked'] = df['embarked'].fillna(df['embarked'].mode()[0])
# # Log transform of uniformity
# In[54]:
sns.distplot(train['fare'])
# In[57]:
df['fare']=np.log(df['fare']+1)
sns.distplot(df['fare'])
# # Correlation
# In[58]:
corr=df.corr()
# In[59]:
plt.figure(figsize=(15,9))
sns.heatmap(corr,annot=True,cmap='coolwarm')
# In[61]:
df.head()
# In[62]:
#dropping more
df = df.drop(columns = ['name','ticket'],axis =1)
df.head()
# In[ ]: