What is iris.target?

QuestionsQuestions8 SkillsProDec, 10 2025
0208

iris.target is an important attribute within the iris dataset object.

Here's a breakdown of what it is:

  • Labels/Target Variable: In the context of machine learning, especially supervised learning, iris.target refers to the labels or target variable for each sample (each flower) in the dataset. It's what we usually want to predict.
  • Species Information: For the Iris dataset specifically, iris.target tells you the species of each Iris flower.
  • Numerical Encoding: The species names (setosa, versicolor, virginica) are not stored as text directly in iris.target. Instead, they are encoded as integers:
    • 0 represents 'setosa'
    • 1 represents 'versicolor'
    • 2 represents 'virginica'
  • NumPy Array: Just like iris.data, iris.target is a NumPy array. It contains 150 integer values, one for each of the 150 flower samples.
  • Correspondence with iris.data: Each integer in iris.target corresponds to the flower measurements (features) in the same row of iris.data. For example, the first number in iris.target is the species of the flower described by the first row in iris.data.

In summary, while iris.data gives you the features (measurements) of each flower, iris.target gives you the answer or category (species) for each flower.

0 Comments

no data
Be the first to share your comment!