Sales=Weight*Advertisement+BiasWeight: the coefficient for the Radio independent variable. In machine learning we call coefficients weights. X: Advertisement here the independent variable. In machine learning we call these variables features. Bias: the intercept where our line intercepts the y-axis. In machine learning we can call intercepts bias. Bias offsets all predictions that we make. Our algorithm will try to learn the correct values for Weight and Bias. By the end of our training, our equation will approximate the line of best fit.
Here sales are depend on advertisement.
Here X is advertisement and Y is Sales. Sample data in csv below.
import numpy as np import pandas as pd import matplotlib.pyplot as plt from sklearn.linear_model import LinearRegression plt.rcParams['figure.figsize'] = (12.0, 9.0) data = pd.read_csv('sales.csv') # load data set X = data['Advertising'].values.reshape(-1, 1) # values converts it into a numpy array Y = data['Sales'].values.reshape(-1, 1) # -1 means that calculate the dimension of rows, but have 1 column print (Y) linear_regressor = LinearRegression() # create object for the class linear_regressor.fit(X, Y) # perform linear regression plt.scatter(X, Y) plt.plot(X, Y, color='green') Y_pred = linear_regressor.predict(X) # make predictions print(Y_pred) plt.plot(X, Y_pred, color='red') plt.show()Here is the output.