0
0
SciPydata~10 mins

Confidence intervals on parameters in SciPy - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to calculate the mean of the data array.

SciPy
import numpy as np

data = np.array([5, 7, 8, 9, 10])
mean_value = np.[1](data)
print(mean_value)
Drag options to blanks, or click blank then click option'
Amedian
Bmean
Csum
Dstd
Attempts:
3 left
💡 Hint
Common Mistakes
Using np.median instead of np.mean
Using np.sum which adds all values instead of averaging
2fill in blank
medium

Complete the code to calculate the standard error of the mean (SEM) for the data.

SciPy
import numpy as np

data = np.array([5, 7, 8, 9, 10])
sem = np.std(data, ddof=1) / np.sqrt([1])
print(sem)
Drag options to blanks, or click blank then click option'
Alen(data) - 1
Bnp.sum(data)
Cnp.mean(data)
Dlen(data)
Attempts:
3 left
💡 Hint
Common Mistakes
Using len(data) - 1 instead of len(data)
Using np.mean(data) or np.sum(data) which are unrelated
3fill in blank
hard

Fix the error in the code to calculate a 95% confidence interval for the mean using scipy.stats.

SciPy
from scipy import stats
import numpy as np

data = np.array([5, 7, 8, 9, 10])
confidence = 0.95
mean = np.mean(data)
sem = stats.sem(data, ddof=1)
margin = sem * stats.t.ppf((1 + confidence) / 2, df=[1])
ci_lower = mean - margin
ci_upper = mean + margin
print(ci_lower, ci_upper)
Drag options to blanks, or click blank then click option'
Alen(data)
Blen(data) + 1
Clen(data) - 1
Dlen(data) - 2
Attempts:
3 left
💡 Hint
Common Mistakes
Using len(data) instead of len(data) - 1 for degrees of freedom
Using len(data) + 1 or len(data) - 2 which are incorrect
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their lengths only if the length is greater than 3.

SciPy
words = ['apple', 'bat', 'carrot', 'dog', 'elephant']
lengths = {word: [1] for word in words if [2]
print(lengths)
Drag options to blanks, or click blank then click option'
Alen(word)
Bword
Clen(word) > 3
Dword > 3
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as the value instead of its length
Checking if the word string is greater than 3 instead of length
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths only if the length is greater than 4.

SciPy
words = ['apple', 'bat', 'carrot', 'dog', 'elephant']
lengths = { [1]: [2] for word in words if [3] }
print(lengths)
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
Clen(word) > 4
Dword.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using word.lower() instead of word.upper() for keys
Using word instead of len(word) for values
Filtering with length greater than 3 instead of 4