Assignment No 3
Assignment No 3
2. Types of Variables
1. Summary statistics:
● What is Statistics?
Statistics is the science of collecting data and analysing them to infer proportions (sample)
that are representative of the population. In other words, statistics is interpreting data in
order to make predictions for the population.
Branches of Statistics:
There are two branches of Statistics.
DESCRIPTIVE STATISTICS : Descriptive Statistics is a statistics or a measure that
describes the data.
INFERENTIAL STATISTICS : Using a random sample of data taken from a population to
describe and make inferences about the population is called Inferential Statistics.
Descriptive Statistics
Descriptive Statistics is summarising the data at hand through certain numbers like mean,
median etc. so as to make the understanding of the data easier. It does not involve any
generalisation or inference beyond what is available. This means that the descriptive
statistics are just the representation of the data (sample) available and not based on any
theory of probability.
Commonly Used Measures
1. Measures of Central Tendency
2. Measures of Dispersion (or Variability)
b. Median : Median is the point which divides the entire data into two equal
halves. One-half of the data is less than the median, and the other half is greater
than the same. Median is calculated by first arranging the data in either ascending
or descending order.
○ If the number of observations is odd, the median is given by the middle
observation in the sorted form.
○ If the number of observations are even, median is given by the mean of the
two middle observations in the sorted form.
An important point to note is that the order of the data (ascending or
descending) does not affect the median.
c. Mode : Mode is the number which has the maximum frequency in the entire data
set, or in other words,mode is the number that appears the maximum number of
times. A data can have one or more than one mode.
● If there is only one number that appears the maximum number of times,
the data has one mode, and is called Uni-modal.
● If there are two numbers that appear the maximum number of times, the
data has two modes, and is called Bi-modal.
● If there are more than two numbers that appear the maximum number of
times, the data has more than two modes, and is called Multi-modal.
Mode is given by the number that occurs the maximum number of times.
Here, 17 and 21 both occur twice. Hence, this is a Bimodal data and the modes
are 17 and 21.
Measures of Dispersion describes the spread of the data around the central value (or the
Measures of Central Tendency)
1. Absolute Deviation from Mean — The Absolute Deviation from Mean, also
called Mean Absolute Deviation (MAD), describes the variation in the data set, in
the sense that it tells the average absolute distance of each data point in the set. It
is calculated as
2. Variance — Variance measures how far are data points spread out from the mean.
A high variance indicates that data points are spread widely and a small variance
indicates that the data points are closer to the mean of the data set. It is calculated
as
4. Range — Range is the difference between the Maximum value and the Minimum
value in the data set. It is given as
5. Quartiles — Quartiles are the points in the data set that divides the data set into
four equal parts. Q1, Q2 and Q3 are the first, second and third quartile of the data
set.
● 25% of the data points lie below Q1 and 75% lie above it.
● 50% of the data points lie below Q2 and 50% lie above it. Q2 is nothing but
Median.
● 75% of the data points lie below Q3 and 25% lie above it.
6. Skewness — The measure of asymmetry in a probability distribution is defined
by Skewness. It can either be positive, negative or undefined.
Positive Skew — This is the case when the tail on the right side of the curve is
bigger than that on the left side. For these distributions, mean is greater than the
mode.
Negative Skew — This is the case when the tail on the left side of the curve is
bigger than that on the right side. For these distributions, mean is smaller than the
mode.
3. Mode
To find mode of all columns
Syntax:
df.mode()
Output:
In the Genre Column mode is Female, for column Age mode is 32 etc. If a
particular column does not have mode all the values will be displayed in
the column.
To find the mode of a specific column.
Syntax:
df.loc[:,'Age'].mode()
Output:
32
4. Minimum
To find minimum of all columns
Syntax:
df.min()
Output:
5. Maximum
To find Maximum of all columns
Syntax:
df.max()
Output:
6. Standard Deviation
To find Standard Deviation of all columns
Syntax:
df.std()
Output:
Output:
2. Types of Variables:
A variable is a characteristic that can be measured and that can assume different values.
Height, age, income, province or country of birth, grades obtained at school and type of
housing are all examples of variables.
● Categorical and
● Numeric.
Each category is then classified in two subcategories: nominal or ordinal for categorical
variables, discrete or continuous for numeric variables.
● Categorical variables
● Numerical Variables
A numeric variable (also called quantitative variable) is a quantifiable characteristic
whose values are numbers (except numbers which are codes standing up for categories).
○ Discrete variables
As opposed to a continuous variable, a discrete variable can assume only a finite
number of real values within a given interval.
An example of a discrete variable would be the score given by a judge to a
gymnast in competition: the range is 0 to 10 and the score is always given to one
decimal (e.g. a score of 8.5)
To create a list that contains a numeric value for each response to the categorical variable.
from sklearn import preprocessing
enc = preprocessing.OneHotEncoder()
enc_df = pd.DataFrame(enc.fit_transform(df[['Genre']]).toarray())
enc_df
6. To display basic statistical details like percentile, mean,standard deviation etc. for
Iris-setosa use describe
print('Iris-setosa')
print(iris[irisSet].describe())
print('Iris-versicolor')
print(iris[irisVer].describe())
10. To display basic statistical details like percentile, mean,standard deviation etc. for
Iris-virginica use describe
print('Iris-virginica')
print(iris[irisVir].describe())
Conclusion:
Descriptive statistics summarises or describes the characteristics of a data set. Descriptive
statistics consists of two basic categories of measures:
Measures of central tendency describe the centre of a data set. It includes the
mean, median, and mode.
Measures of variability or spread describe the dispersion of data within the set and
it includes standard deviation, variance, minimum and maximum variables.
Assignment Questions:
1. Explain Measures of Central Tendency with examples.
2. What are the different types of variables? Explain with examples.
3. Which method is used to statistic the dataframe? write the code.