Python complete tutorial
  • Python Complete Tutorial
  • About this book
  • What you need to prepare
  • 1️⃣Try python for the first time
    • Install python
    • Hello world!
    • Hello world in a nutshell
    • The first simple python project
    • most useful libraries
    • Recommended websites
  • 2️⃣Data structure and basic operations
    • Python data structure
    • Data structure without hash table
    • Data structure with hash table
    • Variability and address
    • basic python programming
    • basic python programming 2
    • basic python programming 3
    • some additions
    • Fibonacci sequence
    • Judging prime numbers
    • txt/csv file operation
  • 🐍Practice program
    • 🚩fancy print
    • 🚩Remove duplicate elements
    • 🚩Palindrome detection
  • 😎leetcode
    • what is leetcode
  • 3️⃣Data mining and machine learning
    • What is data mining
    • iris data set
    • Mean median mode
    • Harmonic mean
    • Histogram
    • Correlation algorithm
    • Gaussian distribution data set
    • projection
    • PCA
    • MDS
    • Bayesian and Frequentist
    • Data normalization
    • binary SVM
    • One Hot Encoding
    • Multi-class SVM
    • Accuracy and error rate
    • Confusion matrix & Accuracy, Precision, Recall
    • F1 score
    • ROC and AUC
  • 4️⃣big data and data visualization
    • line chart
    • Parallel coordinates
    • Histogram chart
  • 5️⃣Mathematical algorithm and digital signal processing
    • Mathematical constants and basic operations
    • Normal distribution
    • Permutation and combination
    • Bernoulli distribution
    • Chaotic system
  • 6️⃣Classes and design patterns
    • Classes and design patterns
  • 7️⃣Operate the database with python
    • MySQL
      • Install MySQL
      • First try MySQL
      • MySQL Architecture
      • database operations
      • database
  • 8️⃣Cryptography
    • beginning of Cryptography
  • 9️⃣deep learning
    • What is Deep Learning
    • basic
  • 💔algorithm
    • Algorithms and Data Structures
Powered by GitBook
On this page
  1. Data mining and machine learning

Histogram

Frequency distribution

The histogram can very vividly show the frequency distribution of data.

For example, the following is the temperature data of a certain place (a total of 100 data, temperature in degrees Celsius)

[27.3 29.5 26.4 24.  26.9 24.7 23.1 28.9 28.2 21.2 24.3 23.7 19.8 25.5
 24.6 16.1 21.9 25.7 25.2 26.1 26.2 24.4 25.8 20.7 22.3 18.9 25.2 27.7
 24.1 22.  26.2 25.5 20.1 24.  22.5 29.9 26.7 25.1 25.  26.7 28.  21.6
 24.5 25.6 22.9 24.5 22.3 21.3 25.1 23.4 18.2 26.5 24.4 26.6 21.6 19.5
 18.2 25.4 25.1 22.6 26.8 24.5 22.1 26.3 27.  24.7 23.5 26.4 24.8 24.6
 24.1 18.8 23.6 20.3 25.3 23.3 20.8 21.7 22.2 25.9 24.2 23.4 23.6 26.1
 24.9 23.7 26.9 20.5 31.1 24.8 29.2 20.8 25.3 23.4 25.7 23.2 28.7 26.
 19.6 25.3]

We plot this data into a histogram as shown below:

temperature = [
    27.3, 29.5, 26.4, 24. , 26.9, 24.7, 23.1, 
    28.9, 28.2, 21.2, 24.3, 23.7, 19.8, 25.5,
    24.6, 16.1, 21.9, 25.7, 25.2, 26.1, 26.2, 
    24.4, 25.8, 20.7, 22.3, 18.9, 25.2, 27.7,
    24.1, 22. , 26.2, 25.5, 20.1, 24. , 22.5, 
    29.9, 26.7, 25.1, 25. , 26.7, 28. , 21.6,
    24.5, 25.6, 22.9, 24.5, 22.3, 21.3, 25.1, 
    23.4, 18.2, 26.5, 24.4, 26.6, 21.6, 19.5,
    18.2, 25.4, 25.1, 22.6, 26.8, 24.5, 22.1, 
    26.3, 27. , 24.7, 23.5, 26.4, 24.8, 24.6,
    24.1, 18.8, 23.6, 20.3, 25.3, 23.3, 20.8, 
    21.7, 22.2, 25.9, 24.2, 23.4, 23.6, 26.1,
    24.9, 23.7, 26.9, 20.5, 31.1, 24.8, 29.2, 
    20.8, 25.3, 23.4, 25.7, 23.2, 28.7, 26. ,
    19.6, 25.3
    ]

import matplotlib.pyplot as plt

plt.hist(temperature, bins=20, facecolor='blue', edgecolor='black', alpha=0.7)

plt.xlabel('temperature')
plt.ylabel('frequency')

plt.title('Temperature detection distribution')

plt.show()

From this figure, we can clearly see the distribution of the data.

The temperature in this area is mostly between 24-26 degrees Celsius, which is comfortable. Occasionally there will be some low temperatures, and you need to prepare a few coats to keep warm.

Statistics

Start time of this page: December 21, 2021

Completion time of this page: December 21, 2021

PreviousHarmonic meanNextCorrelation algorithm

Last updated 3 years ago

3️⃣
Page cover image
Histogram