0% found this document useful (0 votes)
5 views6 pages

Mine 3

The document outlines a procedure for generating a dataset of 50 random age values and performing various statistical computations including mean, median, mode, percentiles, midrange, quartiles, and a five-number summary. It includes Python code to implement these steps and displays the results of the computations. Additionally, it provides a function for users to input their own dataset and compute a specified percentile.

Uploaded by

hudsonnnnn16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views6 pages

Mine 3

The document outlines a procedure for generating a dataset of 50 random age values and performing various statistical computations including mean, median, mode, percentiles, midrange, quartiles, and a five-number summary. It includes Python code to implement these steps and displays the results of the computations. Additionally, it provides a function for users to input their own dataset and compute a specified percentile.

Uploaded by

hudsonnnnn16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

NAME : P KOUSHIK REDDY

ROLL NO : 12212161

Question 1:

STEPS TO BE FOLLOWED :-

let's start with generating a dataset of 50 random age values between 5 and 95 and perform each
computation step-by-step. We can then repeat the experiments as requested.

Step 1: Generate a Dataset

We'll generate 50 random age values between 5 and 95.

Step 2: Perform Computations (a) to (i)

Arrange data in ascending order.

Compute the mean, median, and mode.

Compute a percentile of a data item.

Compute the 70th and 80th percentiles.

Compute the midrange.

Compute the 1st and 3rd quartiles.

Give the five-number summary of the data.

Step 3: Repeat the Experiment

Repeat the above process five times with different datasets.

Step 4: Write a General Program

Create a general program to compute a percentile of a given dataset.

Let's implement this in Python:

INPUT CODE(PYTHON),Along with all the steps as comments :

import numpy as np

import pandas as pd
from scipy import stats

# Step 1: Generate a dataset of 50 random age values between 5 and 95

np.random.seed(42) # For reproducibility

dataset = np.random.randint(5, 96, 50)

# Step 2: Perform computations (a) to (i)

# (a) Arrange data in ascending order

data_sorted = np.sort(dataset)

# (b) Compute mean, median, and mode of the data

mean = np.mean(data_sorted)

median = np.median(data_sorted)

mode = stats.mode(data_sorted)[0][0]

# (c) Compute percentile of a data item from the formed dataset (e.g., 25th percentile)

percentile_25 = np.percentile(data_sorted, 25)

# (d) Compute 70 and 80 percentiles

percentile_70 = np.percentile(data_sorted, 70)

percentile_80 = np.percentile(data_sorted, 80)

# (e) Compute 70th and 80th percentiles (same as above)

percentile_70th = percentile_70

percentile_80th = percentile_80

# (f) Compute midrange of the data

midrange = (np.min(data_sorted) + np.max(data_sorted)) / 2

# (g) Compute 1st and 3rd quartiles of the dataset


quartile_1 = np.percentile(data_sorted, 25)

quartile_3 = np.percentile(data_sorted, 75)

# (h) Find 1st and 3rd quartiles of the dataset (same as above)

quartile_1st = quartile_1

quartile_3rd = quartile_3

# (i) Give five-number summary of the data

five_number_summary = {

"Minimum": np.min(data_sorted),

"1st Quartile": quartile_1,

"Median": median,

"3rd Quartile": quartile_3,

"Maximum": np.max(data_sorted)

# Display the results

"Sorted Data": data_sorted.tolist(),

"Mean": mean,

"Median": median,

"Mode": mode,

"25th Percentile": percentile_25,

"70th Percentile": percentile_70,

"80th Percentile": percentile_80,

"Midrange": midrange,

"1st Quartile": quartile_1st,

"3rd Quartile": quartile_3rd,

"Five-Number Summary": five_number_summary

}
OUTPUT :

Result

{'Sorted Data': [6,

6,

7,

7,

8,

11,

19,

19,

22,

25,

25,

25,

26,

26,

28,

34,

37,

42,

43,

46,

51,

53,

55,

55,

56,

57,

59,

62,

63,
64,

64,

65,

66,

66,

66,

68,

68,

76,

77,

79,

79,

80,

84,

87,

91,

92,

92,

93,

93,

95],

'Mean': 52.36,

'Median': 56.5,

'Mode': 25,

'25th Percentile': 26.0,

'70th Percentile': 66.6,

'80th Percentile': 79.0,

'Midrange': 50.5,

'1st Quartile': 26.0,

'3rd Quartile': 74.0,

'Five-Number Summary': {'Minimum': 6,


'1st Quartile': 26.0,

'Median': 56.5,

'3rd Quartile': 74.0,

'Maximum': 95}}

2)creating a general program to compute the percentile of a given dataset based on user input.

INPUT CODE :

def compute_percentile():

# Accept dataset from the user

data_input = input("Enter the dataset values separated by spaces: ")

data = list(map(int, data_input.split()))

# Accept the percentile value to compute

percentile_value = float(input("Enter the percentile to compute (between 0 and 100): "))

# Compute the requested percentile

percentile_result = np.percentile(data, percentile_value)

return percentile_result

You might also like