-
Notifications
You must be signed in to change notification settings - Fork 7
/
IloveDataScience.py
97 lines (76 loc) · 2.23 KB
/
IloveDataScience.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
#%% [markdown]
# ## This is markdown.
#%%
print("hello world")
print("123")
#%%
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
p = np.linspace(0,20,100)
plt.plot(p,np.sin(p))
plt.show()
#%%
# Let's load and review some data
df = pd.read_csv("./data/pima-data.csv") # load Pima data
df.head(5)
#%% Let's plot the correlation between data columns
import matplotlib.pyplot as plt # matplotlib.pyplot plots data
def draw_corr(df, size = 11):
corr = df.corr() # data frame correlation function
fig, ax = plt.subplots(figsize=(11, 11))
ax.matshow(corr) # color code the rectangles by correlation value
plt.xticks(range(len(corr.columns)), corr.columns) # draw x tick marks
plt.yticks(range(len(corr.columns)), corr.columns) # draw y tick marks
draw_corr(df)
#%%
import plotly.plotly as py
import plotly.graph_objs as go
import numpy as np
x, y, z = np.random.multivariate_normal(np.array([0,0,0]), np.eye(3), 400).transpose()
trace1 = go.Scatter3d(
x=x,
y=y,
z=z,
mode='markers',
marker=dict(
size=12,
color=z, # set color to an array/list of desired values
colorscale='Viridis', # choose a colorscale
opacity=0.8
)
)
data = [trace1]
layout = go.Layout(
margin=dict(
l=0,
r=0,
b=0,
t=0
)
)
fig = go.Figure(data=data, layout=layout)
py.iplot(fig, filename='3d-scatter-colorscale')
#%%
import requests
import os, json, base64
from PIL import Image as pilimage
from urllib.request import urlopen
from IPython.display import Image, HTML, display
URL = "http://www.whateverydogdeserves.com/wp-content/uploads/2016/09/husky-meme-work.jpg"
with urlopen(URL) as response:
with open('temp.jpg', 'bw+') as f:
shutil.copyfileobj(response, f)
Image('temp.jpg')
#%%
def imgToBase64(img):
imgio = BytesIO()
img.save(imgio, 'JPEG')
img_str = base64.b64encode(imgio.getvalue())
return img_str.decode('utf-8')
base64Img = imgToBase64(pilimage.open(test_img))
service_uri = "http://52.190.24.229:80/score"
input_data = json.dumps({'data': base64Img})
headers = {'Content-Type':'application/json'}
result = requests.post(service_uri, input_data, headers=headers).text
print(json.loads(result))