Before trying out linear regression on a real-life dataset, let's understand how we can use the cv2.fitLine function to fit a line to a 2D or 3D point set:
- Let's start by generating some points. We will generate them by adding noise to the points lying on the line :
In [1]: import cv2... import numpy as np... import matplotlib.pyplot as plt... from sklearn import linear_model... from sklearn.model_selection import train_test_split... plt.style.use('ggplot')... %matplotlib inlineIn [2]: x = np.linspace(0,10,100)... y_hat = x*5+5... np.random.seed(42)... y = x*5 + 20*(np.random.rand(x.size) - 0.5)+5
- We can also ...