Show Sidebar Hide Sidebar

# The Iris Dataset in Scikit-learn

This data sets consists of 3 different types of irises’ (Setosa, Versicolour, and Virginica) petal and sepal length, stored in a 150x4 numpy.ndarray

The rows being the samples and the columns being: Sepal Length, Sepal Width, Petal Length and Petal Width.

The below plot uses the first two features. See here for more information on this dataset.

#### New to Plotly?¶

You can set up Plotly to work in online or offline mode, or in jupyter notebooks.
We also have a quick-reference cheatsheet (new!) to help you get started!

### Version¶

In [1]:
import sklearn
sklearn.__version__

Out[1]:
'0.18'

### Imports¶

In [2]:
import plotly.plotly as py
import plotly.graph_objs as go

from sklearn import datasets
from sklearn.decomposition import PCA
import numpy as np


### Calculations¶

In [3]:
# import some data to play with
X = iris.data[:, :2]  # we only take the first two features.
Y = iris.target

x_min, x_max = X[:, 0].min() - .5, X[:, 0].max() + .5
y_min, y_max = X[:, 1].min() - .5, X[:, 1].max() + .5


### Plot the Training Points¶

In [4]:
trace = go.Scatter(x=X[:, 0],
y=X[:, 1],
mode='markers',
marker=dict(color=np.random.randn(150),
size=10,
colorscale='Viridis',
showscale=False))

layout = go.Layout(title='Training Points',
xaxis=dict(title='Sepal length',
showgrid=False),
yaxis=dict(title='Sepal width',
showgrid=False),
)

fig = go.Figure(data=[trace], layout=layout)

In [5]:
py.iplot(fig)

Out[5]:

### Plot the first three PCA dimensions¶

In [6]:
X_reduced = PCA(n_components=3).fit_transform(iris.data)

In [7]:
trace = go.Scatter3d(x=X_reduced[:, 0],
y=X_reduced[:, 1],
z=X_reduced[:, 2],
mode='markers',
marker=dict(
size=6,
color=np.random.randn(150),
colorscale='Viridis',
opacity=0.8)
)
layout=go.Layout(title='First three PCA directions',
scene=dict(
xaxis=dict(title='1st eigenvector'),
yaxis=dict(title='2nd eigenvector'),
zaxis=dict(title='3rd eigenvector'))
)
fig = go.Figure(data=[trace], layout=layout)

In [8]:
py.iplot(fig)

Out[8]:

        Gaël Varoquaux

        BSD 3 clause