Dataset Structure: Features and Labels
In machine learning, every dataset is divided into two main parts:
Features (X)— input variables used by the model to make predictions (e.g., age, height, or number of purchases).Labels (y)— the target variable the model is trying to predict (e.g., whether an email is spam or the price of a house).
In supervised learning, the model learns the relationship between features and labels to make accurate predictions.
Loading a Dataset in Scikit-learn
Scikit-learn includes several built-in datasets for experimentation.
One of the most commonly used is the Iris dataset, which contains measurements of iris flower species.
from sklearn.datasets import load_iris iris = load_iris() # Features (X) - shape: (samples, features) X = iris.data print("Feature shape:", X.shape) print("First row of features:", X[0]) # Labels (y) - shape: (samples,) y = iris.target print("Label shape:", y.shape) print("First label:", y[0])
Inspecting Feature and Label Names
You can check the feature and target names to understand what each column and label represents:
print("Feature names:", iris.feature_names) print("Target names:", iris.target_names)
The following are some key points about features and labels:
-
Featuresare the information your model uses to make predictions. -
Labelsdefine the correct answers during training. -
X: input features, 2D array shape(n_samples, n_features). -
y: target labels, 1D array shape(n_samples,).
Organizing data correctly into X and y is essential for Scikit-learn functions like train_test_split() and .fit().
Proper separation of features and labels is the first step in preparing data for training.
Lessons in this chapter · Machine Learning with Scikit-learn
- 1. Introduction to Scikit-learn
- 2. The Machine Learning Workflow
- 3. Types of ML - Supervised vs Unsupervised
- 4. Dataset Structure - Features and Labels
- 5. Splitting Data - Train vs Test
- 6. ML Workflow and Model Lifecycle
- 7. Feature Scaling and Preprocessing
- 8. Multiple-choice quiz
- 9. Classification with K-Nearest Neighbors
- 10. Regression with Linear Models
- 11. Evaluating Classification Models
- 12. Evaluating Regression Models
- 13. Introduction to Clustering (K-Means)
- 14. What is Cross-Validation?
- 15. Fill-in-the-blank quiz
Understanding Dataset Structure
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help