Python - Python Machine Learning - Mean Median Mode Part 5: Using Mean, Median, and Mode in Machine Learning
Mean, median, and mode are used for different purposes in machine learning:
- Mean: Used in regression models and feature scaling.
- Median: Useful when there are outliers that might skew the mean.
- Mode: Useful for categorical data and probability distributions.
Example 1: Handling Missing Values with Mean
from sklearn.impute import SimpleImputer
import numpy as np
data = [[10], [20], [np.nan], [30]]
imputer = SimpleImputer(strategy='mean')
filled_data = imputer.fit_transform(data)
print(filled_data)
Explanation: Missing values are replaced with the mean of the dataset.