forked from greytip/data-science-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataExplorerTemplate.py
155 lines (78 loc) · 2.47 KB
/
DataExplorerTemplate.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
# coding: utf-8
# In[1]:
# Custom libraries
from datascienceutils import plotter
from datascienceutils import analyze
# Standard libraries
import json
get_ipython().magic('matplotlib inline')
import datetime
import numpy as np
import pandas as pd
import random
from sklearn import cross_validation
from sklearn import metrics
from bokeh.plotting import figure, show, output_file, output_notebook, ColumnDataSource
from bokeh.charts import Histogram
import bokeh
output_notebook(bokeh.resources.INLINE)
from sqlalchemy import create_engine
# In[2]:
irisDf = pd.read_csv('./data/Iris.csv')
# Sample Timeseries picked from here https://www.backblaze.com/b2/hard-drive-test-data.html
hdd2013Df = pd.read_csv('./data/hdd_2013-11-26.csv')
# In[3]:
# Create classes for showing off correlation_analyze's heatmapping ability
def createClasses(x):
rdm = random.random()
if rdm < 0.3:
return 'A'
elif rdm > 0.3 and rdm < 0.6:
return 'B'
else:
return 'C'
irisDf['Class'] = irisDf['Species'].apply(createClasses)
# In[4]:
irisDf.describe()
# In[5]:
irisDf.head()
# In[6]:
irisDf.corr()
# In[7]:
irisDf.select_dtypes(include=[np.number]).columns
# In[8]:
analyze.correlation_analyze(irisDf, exclude_columns='Id',
categories=['Species', 'Class'],
measures=['count', 'SepalLengthCm','SepalWidthCm',
'PetalLengthCm', 'PetalWidthCm'])
# In[9]:
analyze.dist_analyze(irisDf, 'SepalLengthCm')
# In[10]:
analyze.regression_analyze(irisDf, 'SepalLengthCm', 'SepalWidthCm')
# In[11]:
target = irisDf.Species
irisDf.drop(['Species', 'Class'], 1, inplace=True)
# In[12]:
irisDf.head()
# In[13]:
analyze.silhouette_analyze(irisDf, cluster_type='KMeans')
# In[23]:
analyze.silhouette_analyze(irisDf, cluster_type='dbscan')
# In[21]:
analyze.silhouette_analyze(irisDf, cluster_type='spectral')
# In[22]:
analyze.silhouette_analyze(irisDf, cluster_type='birch')
# In[14]:
#analyze.som_analyze(df, (10,10), algo_type='som')
# In[15]:
hdd2013Df.fillna(value=0, inplace=True)
hdd2013Df.describe()
# In[16]:
hdd2013Df.head()
# In[17]:
hdd2013Df['date'] = hdd2013Df['date'].astype('datetime64[ns]')
# In[18]:
hdd2013Df['date'] = [each + datetime.timedelta(0, i*45) for i, each in enumerate(hdd2013Df.date)]
# In[19]:
analyze.time_series_analysis(hdd2013Df, timeCol='date', valueCol='smart_1_raw', seasonal={'freq': '30s'})
# In[ ]: