Change language

Absolute Deviation and Absolute Mean Deviation Using NumPy | python

| | | | |

Rejection:
Rejection — it is a measure of the difference between the observed value of a variable and some other value, often the mean of that variable.

Absolute Deviation:
The absolute deviation of a dataset item — it is the absolute difference between this element and this point. The absolute deviation of observations X1, X2, X3,… .., Xn around the value A is defined as —

For discrete (ungrouped) data

For continuous (ungrouped) data

Absolute mean deviation:
Absolute mean deviation measures spread and spread of data, preferably mean -median-mode-in-python-without-libraries/">median, in terms of absolute deviation. The absolute deviation of observations X1, X2, X3, ……, Xn is minimal when measured around the mean -median-mode-in-python-without-libraries/">median, i.e. A — mean -median-mode-in-python-without-libraries/">median of data. Then the resulting absolute deviation is called the absolute average deviation and is defined as:

For discrete (ungrouped) data — 

For continuous (ungrouped) data — 

Decide:

  1. A dataset with a higher absolute mean deviation (or absolute deviation) has more variability.
  2. A dataset with a lower absolute mean deviation (or absolute deviation) is preferred. 
    -" If there are two datasets with absolute averages AMD1 and AMD2 and AMD1" AMD2, then AMD1 data is considered to have more volatility than AMD2 data.

Example:
Below is the number of candidates enrolled each day within the last 20 days for Python.Engineering -DS & amp; Algo — 
75, 69, 56, 46, 47, 79, 92, 97, 89, 88, 36, 96, 105, 32, 116, 101, 79, 93, 91, 112

Code # 1: Absolute rejection using NumPy

# Import mean , absolute value from numy

from numpy import mean , absolute

 

data = [ 75 , 69 , 56 , 46 , 47 , 79 , 92 , 97 , 89 , 88 ,

36 , 96 , 105 , 32 , 116 , 101 , 79 , 93 , 91 , 112 ]

 
# Suppose any point A about which # absolute deviation is calculated

A = 79

 

sum = 0   # Initialize sum to 0

 
# Absolute deviation calculation

  

for i in range ( len (data)):

av = absolute (data [i] - A)  # Absolute difference value

  # of each data point and A

 

# Sum all these absolute values ​​

sum = sum + av 

 
# Amount divided by the length of data outputs
# absolute rejection

print ( sum / len (data)) 

Exit:

 20.15  

Code # 2: Absolute mean deviation using NumPy

# Import mean , absolute value from numy

from numpy import mean , absolute

 

data = [ 75 , 69 , 56 , 46 , 47 , 79 , 92 , 97 , 89 , 88

36 , 96 , 105 , 32 , 116 , 101 , 79 , 93 , 91 , 112 ]

 
# Absolute mean deviation

mean (absolute (data - mean (data)))

Exit:

20.055

Code # 3: Absolute mean deviation using pandas

# Import pandas library as pd

import pandas as pd

 

data = [ 75 , 69 , 56 , 46 , 47 , 79 , 92 , 97 , 89 , 88 ,

  36 , 96 , 105 , 32 , 116 , 101 , 79 , 93 , 91 , 112 ]

 
# Create a given data data frame

df = pd.DataFrame (data)

  
# Absolute mean deviation

df.mad ()  # mad () - function of mean absolute deviation

Exit:

 20.055 

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

News


Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method