Skip to content

Instantly share code, notes, and snippets.

@dimi-tree
Created May 3, 2015 10:55
Show Gist options
  • Save dimi-tree/942def7766c410bbc43a to your computer and use it in GitHub Desktop.
Save dimi-tree/942def7766c410bbc43a to your computer and use it in GitHub Desktop.
import pandas as pd
df = pd.read_csv(
'http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data',
names = ['sepal length (cm)', 'sepal width (cm)', 'petal length (cm)', 'petal width (cm)', 'class']
)
# store feature matrix in "X"
X = df.drop('class', axis=1).values
levels = {'Iris-setosa': 0, 'Iris-versicolor': 1, 'Iris-virginica':2}
# map 'class' column to numberic and store response vector in "y"
y = df['class'].map(lambda x: levels[x]).values
# check the types of the features and response
print type(X)
print type(y)
# check the shape of the features
print X.shape
# check the shape of the response
print y.shape
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment