In [1]:
from datetime import datetime as dt
import numpy as np
import pandas as pd
# viz libs
import matplotlib.pyplot as plt
%matplotlib inline
import matplotlib.cm as cm
from matplotlib.colors import colorConverter
import plotly.graph_objs as go
from plotly import tools
import plotly.figure_factory as ff
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
init_notebook_mode(connected=True)
random_state=42
nb_start = dt.now()
In [2]:
from sklearn.cluster import KMeans
from sklearn.metrics import silhouette_samples, silhouette_score
In [ ]:
In [ ]:
In [3]:
%%bash
ls -l | grep iris
cat iris.csv | head -2
cat iris.csv | tail -1
In [4]:
df = pd.read_csv('iris.csv', header=None, names=['SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm', 'Species'])
df.info()
In [5]:
df.head()
Out[5]:
In [6]:
df.tail()
Out[6]:
In [ ]:
In [7]:
x = df.SepalLengthCm
y = df.SepalWidthCm
c = df.Species
trace = [go.Scatter(
x = x,
y = y,
marker = dict(
# color = col,
color = c,
colorscale='Viridis',
colorbar=dict(
title='Labels'
),
),
name = 'data',
mode = 'markers',
hoverinfo = 'text',
text = ['x: %s<br>y: %s<br>cluster %i' % (x_i, y_i, c_i) for x_i, y_i, c_i in zip(x, y, c)]
)]
layout = go.Layout(
xaxis = dict({'title': 'x'}),
yaxis = dict({'title': 'y'}),
hovermode='closest',
)
fig = go.Figure(data=trace, layout=layout)
iplot(fig, layout)
In [8]:
x = df.PetalLengthCm
y = df.PetalWidthCm
c = df.Species
trace = [go.Scatter(
x = x,
y = y,
marker = dict(
# color = col,
color = c,
colorscale='Viridis',
colorbar=dict(
title='Labels'
),
),
name = 'data',
mode = 'markers',
hoverinfo = 'text',
text = ['x: %s<br>y: %s<br>cluster %i' % (x_i, y_i, c_i) for x_i, y_i, c_i in zip(x, y, c)]
)]
layout = go.Layout(
xaxis = dict({'title': 'x'}),
yaxis = dict({'title': 'y'}),
hovermode='closest',
)
fig = go.Figure(data=trace, layout=layout)
iplot(fig, layout)
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [9]:
nb_end = dt.now()
'Time elapsed: %s' % (nb_end - nb_start)
Out[9]:
In [ ]: