Mada za sehemu hiiAnalysing dataMada 2
- Performing basic statistical analysis
- Using specialised libraries to analyse data
Statistical analysis is the process of collecting, organizing, and interpreting data to discover patterns and trends. In programming, we use Python libraries to calculate these measures quickly and accurately.
When we work with data, we need simple numbers that summarize the entire dataset. These summary numbers help us understand what typical values look like and how spread out the data is. For example, a shopkeeper might want to know the average daily sales, or a teacher might want to see how students performed on an exam.
There are two main groups of descriptive statistics:
- Measures of Central Tendency – These tell us the center or typical value of the data: mean, median, and mode.
- Measures of Spread (Dispersion) – These tell us how spread out the data is: variance and standard deviation.
Mean (Average)
The mean is the sum of all values divided by the number of values.
Mean=Number of valuesSum of all values
In Python with NumPy:
import numpy as np
data = [15000, 18000, 12000, 20000, 16000]
mean_value = np.mean(data)
print("Mean:", mean_value) # Output: Mean: 16200.0
Median (Middle Value)
The median is the middle value when the data is arranged in order. If there are two middle values, the median is their average.
median_value = np.median(data)
print("Median:", median_value) # Output: Median: 16000.0
Mode (Most Frequent Value)
The mode is the value that appears most often in the dataset.
from scipy import stats
data = [500, 1000, 500, 2000, 500, 1000]
mode_value = stats.mode(data)
print("Mode:", mode_value.mode[0]) # Output: Mode: 500
Variance
Variance measures how far each value in the dataset is from the mean. A higher variance means the data is more spread out.
Variance=n∑(xi−xˉ)2
In Python:
variance_value = np.var(data, ddof=0) # population variance
print("Variance:", variance_value)
Standard Deviation
Standard deviation is the square root of variance. It is often preferred because it is in the same units as the original data.
Standard Deviation=Variance
std_dev = np.std(data, ddof=0) # population standard deviation
print("Standard Deviation:", std_dev)
Note: Use ddof=0 for population data and ddof=1 for sample data.
A Form 4 class in Dar es Salaam scored the following marks in a Computer Studies test:
[65, 72, 48, 90, 55, 78, 62, 70, 45, 88]
Let's calculate the descriptive statistics using Python:
import numpy as np
from scipy import stats
scores = [65, 72, 48, 90, 55, 78, 62, 70, 45, 88]
# Measures of central tendency
mean_score = np.mean(scores)
median_score = np.median(scores)
mode_score = stats.mode(scores)
# Measures of spread
variance_score = np.var(scores, ddof=0)
std_dev_score = np.std(scores, ddof=0)
print("Mean:", mean_score) # 67.3
print("Median:", median_score) # 68.5
print("Mode:", mode_score.mode[0]) # No mode (all unique) - shows first value
print("Variance:", variance_score) # 201.61
print("Std Dev:", std_dev_score) # 14.20
Interpretation:
- The average score is 67.3 marks.
- Half of the students scored above 68.5 and half scored below.
- The standard deviation of 14.20 tells us that most scores fall within 14.20 marks of the mean (between 53.1 and 81.5).
When working with larger datasets stored in files, we use Pandas to load and analyze data:
import pandas as pd
# Load data from a CSV file
df = pd.read_csv('student_scores.csv')
# Calculate statistics for a column
print("Mean:", df['Score'].mean())
print("Median:", df['Score'].median())
print("Std Dev:", df['Score'].std())
print("Summary:")
print(df['Score'].describe())
When we calculate these statistics, we learn about the distribution of our data:
- If mean equals median, the data may be symmetric (normal distribution).
- If mean is greater than median, the data is skewed to the right (a few high values).
- If mean is less than median, the data is skewed to the left (a few low values).
- A low standard deviation means data is clustered near the mean.
- A high standard deviation means data is spread out.
Understanding distribution helps us make better decisions based on the data.
In Tanzania, small business owners can use basic statistics to understand their daily sales. For example, a market vendor in Kariakoo can record daily sales for a month, calculate the mean to know the average income, and use standard deviation to see which days have the most variation — helping them plan stock purchases and manage cash flow more effectively.
Jinsi utakavyotathminiwaTathmini ya mchakato · Tathmini ya matokeo · Tathmini ya maarifa
Tathmini ya mchakato
- Compute descriptive statistics using Python libraries.
- Identify appropriate statistical measures forgiven data.
Tathmini ya matokeo
A report summarizing key statistical insights (e.g., central tendency, variability, distribution).
Tathmini ya maarifa
Detailed knowledge of:
Method used: The student should explain
- demonstrate step-by-step the statistical computations.
Principles: The student should explain the principles of:
- Central tendency, dispersion, and inferential statistics.
Theories: The student should explain:
- Different statistical methods
- Importance of statistical significance.
Circumstantial knowledge:
Detailed knowledge about:
- Patterns in datasets and interpreting variability.
Swali
Statistical analysis is defined in the lesson as:
Ingia ili kuwasilisha jibu lako na lihesabiwe katika umahiri wako.
Ingia ili kufanya mazoeziMwalimu
Umekwama? Niulize chochote kuhusu mada hii.
Ingia ili kumuuliza Mwalimu wa AI wa Sonza kuhusu swali hili.
Ingia ili kuulizaMajadiliano
Hakuna maswali bado