 # Exploring categorical data

Such variables take a fixed and limited number of possible values. For example, classes, gender, blood type, etc. Also, in the case of categorical variables, the logical order does not match the categorical data, for example, “one”, “two”, “three”. But the sorting of these variables uses a logical order. For example, gender is a categorical variable and has categories — male and female, and there is no internal order in the categories. A purely categorical variable — it is a variable that allows you to simply assign categories, but you cannot clearly order the variables.

Terms related to volatility metrics:

• Mode: most frequent value in data
Example-
` Data = ["Car", "Bat", "Bat", "Car", " Bat "," Bat "," Bat "," Bike "] Mode =" Bat "`
• Expected value: When working in machine learning, the categories must be linked with a numerical value to give an understanding of the machine. This gives an average based on the likelihood of the category appearing, i.e. expected value.
Calculated by —
` - & gt; Multiply each outcome by its probability of occurring. - & gt; Sum these values ​​`

Thus, the sum of the values ​​multiplied by the probability of their occurrence is often used to sum the levels of variable factors.

• • Histograms: the frequency of each category, presented as columns.

` `

``` import matplotlib.pyplot as plt import numpy as np ```

` `

Data —

Indexing data —

 ` label ` ` = ` ` [` ` `Car` ` `, ` `` B ike` ` `, ` ` `Truck` ` `, ` ` `Cycle` ` `, ` `` Jeeps` ` `, ` ` `Amulance` ` `] ` ` no_vehicle = [ 941 , 854 , 4595 , 2125 , 942 , 509 ] ```` ```
 ` index ` ` = ` ` np.arange (` ` len ` ` (label)) `   ` print ` ` (` ` "Total Labels:" ` `, ` ` len ` ` (label)) ` ` print ` ` (` `" Indexing: "` `, index) `

Exit :

` Total Labels: 6 Indexing: [0 1 2 3 4 5] `

Histogram —

 ` plt.bar (index, no_vehicle) ` ` plt.xlabel (` ` `Type` ` `, fontsize ` ` = ` ` 15 ` `) ` ` plt.ylabel (` ` `No of Vehicles` ` `, fontsize ` ` = ` ` 15 ` `) ` ` plt.xticks (index, label, fontsize ` ` = ` ` 10 ` `, rotation ` ` = ` ` 30 ` `) ` ` plt.title (` ` `Market Share for Each Genre 1995-2017` ` `) ` `   plt.show () ```` ```

Exit:

•  Pie charts: The frequency of each category, represented as pie charts. It is a pie chart where the arc length of each slice is proportional to the amount it represents.

 ` plt.figure (figsize ` ` = ` ` (` ` 8 ` `, ` ` 8 ` `)) ` ` plt.pie (no_vehicle, labels ` ` = ` ` label, ` ` ` ` startangle ` ` = ` ` 90 ` `, autopct ` ` = ` ``% .1f %% `` `) ` ` plt.show () `

Output: