Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

datasets.load_iris() in Python

Tags:

python

dataset

What does the function load_iris() do ? Also, I don't understand what type of data it contains and where to find it.

iris = datasets.load_iris() 
X = iris.data 
target = iris.target 
names = iris.target_names

Can somebody please tell in detail what does this piece of code does? Thanks in advance.

like image 813
LenushK Avatar asked Apr 01 '17 17:04

LenushK


1 Answers

To thread off the previous comments and posts from above, wanted to add another way to load iris() besides iris = datasets.load_iris()

from sklearn.datasets import load_iris
iris = load_iris()

Then, you can do:

X = iris.data 
target = iris.target 
names = iris.target_names

And see posts and comments from other people here.

And you can make a dataframe with :

df = pd.DataFrame(X, columns=iris.feature_names)
df['species'] = iris.target
df['species'] = df['species'].replace(to_replace= [0, 1, 2], value = ['setosa', 'versicolor', 'virginica'])
like image 119
S.Doe_Dude Avatar answered Nov 02 '22 06:11

S.Doe_Dude