bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
Learn/Python/Data Science and Scientific Python
Python•Data Science and Scientific Python

Machine Learning - Data Distribution

Data Distribution

Earlier in this tutorial we have worked with very small amounts of data in our examples, just to understand the different concepts.

In the real world, the data sets are much bigger, but it can be difficult to gather real world data, at least at an early stage of a project.

How Can we Get Big Data Sets?

To create big data sets for testing, we use the Python module NumPy, which comes with a number of methods to create random data sets, of any size.

Example

import numpy
x = numpy.random.uniform(0.0, 5.0, 250)

print(x)

Histogram

To visualize the data set we can draw a histogram with the data we collected.

We will use the Python module Matplotlib to draw a histogram.

Learn about the Matplotlib module in our Matplotlib Tutorial .

Example

import numpy
import matplotlib.pyplot as plt
x =
numpy.random.uniform(0.0, 5.0, 250)
plt.hist(x, 5)
plt.show()

Histogram Explained

We use the array from the example above to draw a histogram with 5 bars.

The first bar represents how many values in the array are between 0 and 1.

The second bar represents how many values are between 1 and 2.

Etc.

Which gives us this result

  • 52 values are between 0 and 1
  • 48 values are between 1 and 2
  • 49 values are between 2 and 3
  • 51 values are between 3 and 4
  • 50 values are between 4 and 5

Note

The array values are random numbers and will not show the exact same result on your computer.

Big Data Distributions

An array containing 250 values is not considered very big, but now you know how to create a random set of values, and by changing the parameters, you can create the data set as big as you want.

Example

import numpy
import matplotlib.pyplot as plt
x =
numpy.random.uniform(0.0, 5.0, 100000)
plt.hist(x, 100)
plt.show()

Previous

Matplotlib Markers

Next

Matplotlib Line

This chapter

Overview
38

Lessons

159m

Read time

1. NumPy Tutorial2. Matplotlib Tutorial3. Machine Learning4. Pandas Tutorial5. Matplotlib Getting Started6. Machine Learning - Mean Median Mode7. Matplotlib Pyplot8. Machine Learning - Standard Deviation9. Matplotlib Plotting10. Machine Learning - Percentiles11. Matplotlib Markers12. Machine Learning - Data Distribution13. Matplotlib Line14. Machine Learning - Normal Data Distribution15. Matplotlib Labels and Title16. Machine Learning - Scatter Plot17. Matplotlib Adding Grid Lines18. Machine Learning - Linear Regression19. Matplotlib Subplot20. Machine Learning - Polynomial Regression21. Matplotlib Scatter22. Machine Learning - Multiple Regression23. Matplotlib Bars24. Machine Learning - Scale25. Matplotlib Histograms26. Machine Learning - Train/Test27. Matplotlib Pie Charts28. Machine Learning - Decision Tree29. Machine Learning - Confusion Matrix30. Machine Learning - Hierarchical Clustering31. Machine Learning - Logistic Regression32. Machine Learning - Grid Search33. Preprocessing - Categorical Data34. Machine Learning - K-means35. Machine Learning - Bootstrap Aggregation (Bagging)36. Machine Learning - Cross Validation37. Machine Learning - AUC - ROC Curve38. Machine Learning - K-nearest neighbors (KNN)

On this page

Data DistributionHow Can we Get Big Data Sets?HistogramHistogram ExplainedBig Data Distributions