codegurukool.com · Free coding tutorials & online compiler

Home › Python Tutorial › Python statistics and machine learning basics

Python statistics and machine learning basics

Mean, median, mode and spread.

Machine learning starts with describing data. The statistics module gives the mean (average), median (middle value), mode (most common) and standard deviation (spread). Later steps use libraries like scikit-learn for regression, decision trees and clustering.

Example code

import statistics as st
data = [2, 3, 3, 5, 7]
print(st.mean(data), st.median(data), st.mode(data))
print(round(st.stdev(data), 2))

Run this code in the online editor

← NumPy, Pandas and MatplotlibPython data structures and algorithms →