# Python program to find out best fit line in Linear Regresion by Predicting Y

## Making predictions on Y to draw line

Our prediction function outputs an estimate of sales based on advertising and our current values for Weight and Bias.
```Sales=Weight*Advertisement+Bias
```
Weight: 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 X is advertisement and Y is Sales. Sample data in csv below. Python program to fit the the line by predicting sales
```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)

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. Predicted values are here 