Machine Learning (ML) in Python utilizes a rich scientific software stack (NumPy, Pandas, SciPy, Scikit-Learn, Matplotlib) to build predictive models from observational data.
flowchart LR
A["Raw Data Collection"] --> B["Data Cleaning & Preprocessing"]
B --> C["Feature Scaling & Train/Test Split"]
C --> D["Model Selection & Training"]
D --> E["Evaluation & Metrics"]
import numpy as np
from typing import Dict, Any
def demonstrate_ml_data_structure() -> Dict[str, Any]:
"""Construct a standard feature matrix (X) and target vector (y)."""
# Feature Matrix X: 4 samples, 2 features (Age, Income)
X = np.array([
[25, 50000],
[30, 60000],
[35, 75000],
[40, 90000]
], dtype=np.float64)
# Target Vector y: Binary classification (0: No Purchase, 1: Purchase)
y = np.array([0, 0, 1, 1], dtype=np.int32)
return {
"num_samples": X.shape[0],
"num_features": X.shape[1],
"X_mean": np.mean(X, axis=0),
"y_labels": y
}
if __name__ == "__main__":
info = demonstrate_ml_data_structure()
print(f"Feature Matrix Samples: {info['num_samples']}, Features: {info['num_features']}")
print(f"Feature Means (Age, Income): {info['X_mean']}")
(n_samples, n_features). Target vectors ($y$) are typically 1D of shape (n_samples,).Create a 2D NumPy feature array $X$ of shape (5, 3) with random float values and print its shape and mean.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
You've completed this section! Take a quick 5-question quiz to check your understanding.