Skip to content
def mean(data):
    return sum(data) / len(data)

def median(data):
    sorted_data = sorted(data)
    n = len(sorted_data)
    if n % 2 == 0:
        return (sorted_data[n//2 - 1] + sorted_data[n//2]) / 2
    else:
        return sorted_data[n//2]

import matplotlib.pyplot as plt

def histogram(data, bins=8):
    plt.hist(data, bins=bins, edgecolor='black')
    plt.xlabel('Value')
    plt.ylabel('Frequency')
    plt.title('Histogram')
    plt.show()

import matplotlib.pyplot as plt

def box_and_whisker_plot_rotated(data):
    plt.boxplot(data, vert=False)
    plt.xlabel('Data')
    plt.ylabel('Value')
    plt.title('Box and Whisker Plot')
    plt.show()

import math

def standard_deviation(data):
    mean_val = mean(data)
    variance = sum((x - mean_val) ** 2 for x in data) / len(data)
    return math.sqrt(variance)

data = [23,45,16,75,32,35,28,35]

print("Mean:", mean(data))
print("Median:", median(data))
histogram(data)
box_and_whisker_plot_rotated(data)
print("Standard Deviation:", standard_deviation(data))

from collections import Counter

def mode(data):
    data_counter = Counter(data)
    mode_count = max(data_counter.values())
    mode_values = [val for val, count in data_counter.items() if count == mode_count]
    return mode_values

def data_range(data):
    return max(data) - min(data)
data = [23,45,16,75,32,35,28,35]

print("Mode:", mode(data))
print("Range:", data_range(data))

import numpy as np

def lower_quartile(data):
    return np.percentile(data, 25)

def upper_quartile(data):
    return np.percentile(data, 75)

data = [23,45,16,75,32,35,28,35]

print("Lower Quartile (Q1):", lower_quartile(data))
print("Upper Quartile (Q3):", upper_quartile(data))

import numpy as np
from scipy import stats

def identify_outliers_zscore(data, threshold=3):
    z_scores = np.abs(stats.zscore(data))
    outliers = np.where(z_scores > threshold)
    return outliers[0]

data = [23,45,16,75,32,35,28,35]
outlier_indices = identify_outliers_zscore(data)
print("Outlier indices:", outlier_indices)