Change language

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 —
     -" Multiply each outcome by its probability of occurring. -" 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.

    Library downloads —

    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:

Shop

Gifts for programmers

Learn programming in R: courses

$FREE
Gifts for programmers

Best Python online courses for 2022

$FREE
Gifts for programmers

Best laptop for Fortnite

$399+
Gifts for programmers

Best laptop for Excel

$
Gifts for programmers

Best laptop for Solidworks

$399+
Gifts for programmers

Best laptop for Roblox

$399+
Gifts for programmers

Best computer for crypto mining

$499+
Gifts for programmers

Best laptop for Sims 4

$

Latest questions

PythonStackOverflow

Common xlabel/ylabel for matplotlib subplots

1947 answers

PythonStackOverflow

Check if one list is a subset of another in Python

1173 answers

PythonStackOverflow

How to specify multiple return types using type-hints

1002 answers

PythonStackOverflow

Printing words vertically in Python

909 answers

PythonStackOverflow

Python Extract words from a given string

798 answers

PythonStackOverflow

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

606 answers

PythonStackOverflow

Python os.path.join () method

384 answers

PythonStackOverflow

Flake8: Ignore specific warning for entire file

360 answers

News


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

How to specify multiple return types using type-hints

Printing words vertically in Python

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically