<jupyter_start><jupyter_text>Mean- the mean of a numerical data set is a measure of it's centre- it is also known as the average- it is calculated by adding all the data values and then dividing the sum by the number of data values.- $\Large\frac{sum  of  values}{number of values}$ Median- The Median is the middle value when all values are arranged in a numerical order- if there are two middle values, the median is the average of the two middle values Mode- The mode is the most popular or most common value- it has the highest frequency- there may be more than one mode Range- the range measures of the spread of the data set- it is the difference between the largest data value and the smallest data value**Outliners** are where one or two values are much samller or larger than the other values on the set.**Which measure of the centre is most useful?**- the mean is appropriate when there are no extreme values or outliners distort the picture - the median is appropriate when outliners are present- the mode is appropriate when the most common result is significantSummary or measures of Centre===ModeMedianMeanThe Most common value or category. It tells us nothing about the rest of the data. Data may have no mode or one mode or more than one modeThe Score in the exact middle of the value placed in numerical order. It tells us nothing about other values. it is uneffected by outliersUses all the scores a total, divided by the number of the score. it is affected by outliers<jupyter_code>import math
import numpy as np
import pandas as pd
from scipy import stats
first_ex = np.array([6,2,4,3,1,4,5,4,16,5])

print("Mean : ",np.mean(first_ex))
print("Median : ",np.median(first_ex))
print("Mode : ", stats.mode(first_ex)[0])
print("Range :",  np.ptp(first_ex)) # axis can be added for array of arrays


def outliers(data, m=2):
    return data[abs(data - np.mean(data)) >= m * np.std(data)]

print("Outliers :",outliers(first_ex))


df = pd.DataFrame(first_ex)
df.boxplot();<jupyter_output>Mean :  5.0
Median :  4.0
Mode :  [4]
Range : 15
Outliers : [16]<jupyter_text>- I can calculate and interpret the mode and range for the set of data **5.3**- I can calculate and interpret the mean and median for the set of data **5.4**- I can explain the effect of individual data values, including outliers, on the range, mean and median **5.5** All answers are to be given correct to decimal place, unless otherwise specified. 1- Calculate the mean and mode of each data set<jupyter_code>first_a_q = np.array([1,1,3,5,5,5,10])
first_a_q_mean = np.mean(first_a_q)

print(first_a_q)
print("Mean : ", round(first_a_q_mean,ndigits=1))
print("Mode : ", stats.mode(first_a_q)[0])

print()
print("==========================")
first_b_q = np.array([4,4,4,7,8,8,10,11])
first_b_q_mean = np.mean(first_b_q)

print(first_b_q)
print("Mean : ", round(first_b_q_mean,ndigits=1))
print("Mode : ", stats.mode(first_b_q)[0])<jupyter_output>[ 1  1  3  5  5  5 10]
Mean :  4.3
Mode :  [5]

==========================
[ 4  4  4  7  8  8 10 11]
Mean :  7.0
Mode :  [4]<jupyter_text>2- In a football season, the number of kicks Kiy made each week was<jupyter_code>second_q = np.array([22,16,18,31,10,8,19,16,18,12,10,9,16])
print(second_q)
print('average (mean) : ', round(np.mean(second_q),ndigits= 1) )<jupyter_output>[22 16 18 31 10  8 19 16 18 12 10  9 16]
average (mean) :  15.8<jupyter_text>3- In three races Paula recorded the times 25.1 seconds 24.8 and 24.1 seconds.a) What is the mean time of the races ? Round to two decimal placesb) Find the median time<jupyter_code>third_q = np.array([25.1, 24.8, 24.1])
print("A - ", round(np.mean(third_q),ndigits=2))
print("B - ", np.median(third_q))<jupyter_output>A -  24.67
B -  24.8<jupyter_text>4- Lily obtained the following scores on her first five Maths tests: 92 89 94 82 93A) What is her mean test score B) if there is one more test left to complete, and she wants to achieve an average of at least 85, what is the lowest score Lily can obtain for her final test<jupyter_code>fourth_a_q  = np.array([92,89,94,82,93])
fourth_a_q_mean = np.mean(fourth_q)

print('A- ', round(fourth_q_mean, ndigits=2))

fourth_b_q_targeted = (len(fourth_q) +1 ) * 85
fourth_b_q_current = sum(fourth_q)

print("Minimum score required to get average 85 is ", fourth_b_q_targeted- fourth_b_q_current)<jupyter_output>A-  90.0
Minimum score required to get average 85 is  60<jupyter_text>5- This Data contains six houses prices in Darwina) Which price would considered the outlierb) If the outlier was removed from the data set, by now how much would the median change ? First work out the median for each casec) If outlier was removed from the dataset by how much would the mean change, to the nearest dollar? first work out the mean for each case.<jupyter_code>six_q = np.array([324000, 289000, 431000, 295000, 385000, 1700000])
print(six_q)
print()
outlier = outliers(six_q)
if(len(outlier) > 0 ):
    print("A- Price considered the outliers ", outlier)
else:
    print("A- There is no outliers")
#six_q_index =np.where(six_q == outlier)[0][0]
#six_q_removedoutlier = np.delete(six_q,six_q_index)

six_q_removedoutlier = np.setdiff1d(six_q,outlier)

print()
print('B- Median with outlier {:,}'.format(np.median(six_q)) , 'Median without outlier {:,}'.format( np.median(six_q_removedoutlier)))
print('B- Median change {:,}'.format(abs(np.median(six_q) - np.median(six_q_removedoutlier))))
print()
print('C- Mean with outlier {:,}'.format(np.mean(six_q)) , 'MEan without outlier {:,}'.format( np.mean(six_q_removedoutlier)))
print('C- Mean Change {:,}'.format(round( abs(np.mean(six_q) - np.mean(six_q_removedoutlier)))))<jupyter_output>[ 324000  289000  431000  295000  385000 1700000]

A- Price considered the outliers  [1700000]

B- Median with outlier 354,500.0 Median without outlier 324,000.0
B- Median change 30,500.0

C- Mean with outlier 570,666.6666666666 MEan without outlier 344,800.0
C- Mean Change 225,867.0<jupyter_text>6- The Number of strokes scored on the 18th hole golf course was recorded for a number of golfers. The results are shown opposite.a) How many players had their score recorded ?b) What is the average score ?c) How many players took fewer strokes then the averaged) What number of strokes is mode ?<jupyter_code>data_q_6 = {'Strokes':  [2,3,4,5,6,],
        'Players': [1,6,27,20,10,],
        }
print(df_q_6)
df_q_6 = pd.DataFrame (data_q_6, columns = ['Strokes','Players'])
df_q_6['TotalStroke'] = df_q_6.apply(lambda x : x.Strokes * x.Players, axis=1)


print('a-',df_q_6.Players.sum(),' players')
average_q_6 = df_q_6.TotalStroke.sum() /df_q_6.Players.sum()
print('b- average',average_q_6)
print('c-', df_q_6[df_q_6.Strokes < average_q_6 ].Players.sum())
print('d-', df_q_6[df_q_6.Players == df_q_6.Players.max()].iloc[0].Strokes)<jupyter_output>a- 64  players
b- average 4.5
c- 34
d- 4
{'fraction_non_alphanumeric': 0.12014030985092078, 'fraction_numerical': 0.053931598947676115, 'mean_word_length': 4.9246753246753245, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '618622', 'license': 'MIT', 'n_tokens_mistral': 2653, 'n_tokens_neox': 2337, 'n_words': 845, 'path': 'notebooks/Year9-Statistics.ipynb', 'repo_name': 'mmercan/study_python', 'size': '6842'}