We can help understand data by building mathematical models, this is key to machine learning. One of such models is linear regression, in which we fit a line to (x,y) data.

There are many modules for Machine Learning in Python, but scikit-learn is a popular one.

import matplotlib.pyplot as plt import numpy as np

randomNumberGenerator = np.random.RandomState(1000) x = 4 * randomNumberGenerator.rand(100) y = 4 * x - 1 + randomNumberGenerator.randn(100) plt.scatter(x, y); plt.show()

This will create a bunch of random data, which follows a linear path. In a real life situation, you would use real world data instead of random numbers

We then use the model linear regression from the scikit-learn module.

model = LinearRegression(fit_intercept=True) model.fit(x[:, np.newaxis], y)

then we define the linear space and predict the y values using the model.

finally we plot the data, summarizing with this code:

# pythonprogramminglanguage.com from sklearn.linear_model import LinearRegression import matplotlib matplotlib.use('qt5agg')

import matplotlib.pyplot as plt import numpy as np

# Create random data randomNumberGenerator = np.random.RandomState(1000) x = 4 * randomNumberGenerator.rand(100) y = 4 * x - 1 + randomNumberGenerator.randn(100)

# Create model model = LinearRegression(fit_intercept=True) model.fit(x[:, np.newaxis], y)