DA Lab ANSWERS
DA Lab ANSWERS
1. Implement the following functions in the list of BMI values for people living in a rural area
bmi_list = [29, 18, 20, 22, 19, 25, 30, 28,22, 21, 18, 19, 20, 20, 22, 23]
(i) random.choice()
(ii) random.sample()
(iii) random.randint()
PROGRAM:
import random
from random import sample
def BMI(height, weight):
bmi = weight/(height**2)
return bmi
bmi_list = [29, 18, 20, 22, 19, 25, 30, 28,22, 21, 18, 19, 20, 20, 22, 23]
height = 1.79832
weight = 70
bmi= BMI(height, weight)
print("The BMI is", format(bmi), "so ", end='')
if (bmi < 18.5):
print("underweight")
(i) random.choice()
print(random.choice(bmi_list))
output:
30
In [98]:
Page 1 of 10
(ii)random.sample()
print(sample(bmi_list,3))
(iii)random.randint()
print(random.randint(0, 12))
output: 9
2. Use the random.choices() function to select multiple random items from a sequence with
repetition.
For example, You have a list of names, and you want to choose random four names from it,
and it’s okay for you if one of the names repeats.
PROGRAM:
import random
print(sample_list3)
Output:
['Novac', 'Novac', 'Martina', 'Sarena']
3. Write a Python program to demonstrate the use of sample() function for string and tuple
types.
import random
Page 2 of 10
tuple1 = ("Selshia", "AI", "computer", "science", "Jansons", "Engineering", "btech")
output:
With tuple: ['Jansons', 'Selshia', 'btech', 'Engineering']
4. Write a python script to implement the Z-Test for the following problem:
A school claimed that the students’ study that is more intelligent than the average school.
On calculating the IQ scores of 50 students, the average turns out to be 11. The mean of
the population IQ is 100 and the standard deviation is 15. Check whether the claim of
principal is right or not at a 5% significance level.
PROGRAM:
import math
import numpy as np
mean_iq = 110
sd_iq = 15/math.sqrt(50)
alpha =0.05
null_mean =100
data = sd_iq*randn(50)+mean_iq
else:
OUTPUT:mean=109.65 stdv=2.06
Reject Null Hypothesis
Page 3 of 10
5. Write a Python program to demonstrate the ‘T-Test’ with suitable libraries for a sample
student’s data. (Create and use dataset of your own)
import pandas as pd
print(tscore,pvalue) if (pvalue>alpha):
output:
6. Import the necessary libraries in Python for implementing ‘One-Way ANOVA Test’ in a
sample dataset. (Create and use dataset of your own)
Program:
import pandas as pd
df = pd.read_csv("https://reneshbedre.github.io/assets/posts/anova/onewayanova.txt",
sep="\t")
# generate a boxplot to see the data distribution by treatments. Using boxplot, we can
Page 4 of 10
ax = sns.barplot(x='treatments', y='value', data=df_melt)
plt.show()
output:
7. Import the necessary libraries in Python for implementing Two-Way ANOVA Test’ in a
sample dataset. (Create and use dataset of your own)
8. Let us consider a dataset where we have a value of response y for every feature x:
PROGRAM:
Page 5 of 10
import numpy as np
# number of observations/points
n = np.size(x)
m_x = np.mean(x)
m_y = np.mean(y)
Page 6 of 10
plt.xlabel('x')
plt.ylabel('y')
plt.show()
def main():
x = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
b = estimate_coef(x, y)
print("Estimated coefficients:\nb_0 = {} \
plot_regression_line(x, y, b)
if __name__ == "__main__":
main()
OUTPUT:
Estimated coefficients:
b_0 = 1.2363636363636363
b_1 = 1.1696969696969697
9. Import scipy and draw the line of Linear Regression for the following data:
x = [5,7,8,7,2,17,2,9,4,11,12,9,6]
Page 7 of 10
y = [99,86,87,88,111,86,103,87,94,78,77,85,86]
Where the x-axis represents age, and the y-axis represents speed. We have registered the
age and speed of 13 cars as they were passing a tollbooth.
PROGRAM:
x = [5,7,8,7,2,17,2,9,4,11,12,9,6]
y = [99,86,87,88,111,86,103,87,94,78,77,85,86]
def myfunc(x):
plt.scatter(x, y)
plt.plot(x, mymodel)
plt.xlabel('Age')
plt.ylabel('Speed Of Cars')
plt.show()
OUTPUT:
Page 8 of 10
Implement the time series analysis concept for a sample dataset using Pandas.
10. (Create and use dataset of your own)
12. Demonstrate various time series models using Python.(Create and use dataset of your own)
PROGRAM:
df = pd.read_csv('https://raw.githubusercontent.com/selva86/datasets/master/a10.csv',
parse_dates=['date'], index_col='date')
# Draw Plot
plt.figure(figsize=(16,5), dpi=dpi)
plt.plot(x, y, color='tab:red')
plt.show()
OUTPUT:
Page 10 of 10