0% found this document useful (0 votes)
6 views5 pages

ML2 NDassignment

Uploaded by

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

ML2 NDassignment

Uploaded by

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

import pandas as pd

import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

tb = pd.read_csv('ML2.csv')
tb.head()

Subject number Data-1 (LG) Data2 (HG)


0 1 2.63 8.88
1 2 1.87 8.99
2 3 2.46 3.95
3 4 1.82 4.36
4 5 2.14 7.00

#QUES 1 (A)-> Draw and compare histograms of these two groups of tumor
data (Data1(LG) and Data2(HG)).
# Extract the tumor data
data1_lg = ['Data-1 (LG)']
_
data2_hg = ['Data2 (HG)']

# Histogram for Data-1 (LG)


tb.hist(data1_lg, bins=9, color='green', alpha=0.5, label='LG (Low
Grade)')
_
#Histogram for Data-2 (HG)
tb.hist(data2_hg, bins=9, color='yellow', alpha=0.5, label='HG (High
Grade)')

array([[<Axes: title={'center': 'Data2 (HG)'}>]], dtype=object)


#QUES 1 (B)-> Compare box and whisker plots of these two groups of
data.
tb.boxplot(data1_lg, patch_artist=True,
boxprops=dict(facecolor='blue', color='blue'),
medianprops=dict(color='black'))
tb.boxplot(data2_hg, patch_artist=True, boxprops=dict(facecolor='red',
color='red'), medianprops=dict(color='black'))

<Axes: >

#The box plot for LG tumors shows a smaller range with fewer outliers,
indicating lower variability in tumor sizes.
#The box plot for HG tumors, on the other hand, displays a wider
range, highlighting greater variability in the sizes

#Ques-2 -> A)Take input from user (list of "ANY" 10 elements)


#B)Find the size of the list
#C) Sort the given list in ascending or descending form
#D) Calculate the following :-(i) Mean (ii) Median (iii) Mode (iv)
Variance (v) 90 percentile value

import statistics as stats


user_input = input("Enter 10 elements separated by spaces: ")
user_list = [int(i) for i in user_input.split()]

# Check if the user has entered exactly 10 elements


if len(user_list) != 10:
print("Please enter exactly 10 elements!")
else:
# B. Find the size of the list
size_of_list = len(user_list)
print("Size of the list:", size_of_list)

Enter 10 elements separated by spaces: 10 23 43 2 6 7 8 10 4 1

Size of the list: 10

# C. Sort the list (ask user for ascending or descending)


sort_order = input("Enter 'asc' for ascending or 'desc' for descending
sort: ")
_
if sort_order == 'asc':
sorted_list = sorted(user_list)
print("Sorted list in ascending order:", sorted_list)
elif sort_order == 'desc':
sorted_list = sorted(user_list, reverse=True)
print("Sorted list in descending_order:", sorted_list)
else:
print("Invalid sort order input. Please enter 'asc' or 'desc'.")

Enter 'asc' for ascending or 'desc' for descending sort: asc

Sorted list in ascending order: [1, 2, 4, 6, 7, 8, 10, 10, 23, 43]

# D. Calculate statistical metrics


# (i) Mean
mean_value = np.mean(user_list)
print("Mean:", mean_value)

Mean: 11.4

# (ii) Median
median_value = np.median(user_list)
print("Median:", median_value)

Median: 7.5

# (iii) Mode
try:
mode_value = stats.mode(user_list)
print("Mode:", mode_value)
except stats.StatisticsError:
print("No mode found, all values appear only once.")

Mode: 10

# (iv) Variance
variance_value = np.var(user_list)
print("Variance:", variance_value)

Variance: 144.84

# (v) 90th percentile


percentile_90 = np.percentile(user_list, 90)
print("90th Percentile:", percentile_90)

90th Percentile: 24.999999999999993

You might also like