/Advertising

Using Linear Regression for a sales prediction

Primary LanguageJupyter Notebook

Advertising Using Linear Regression for a sales prediction Libraries: import pandas as pd import seaborn as sns import matplotlib.pyplot as plt from sklearn.preprocessing import StandardScaler from sklearn.linear_model import LinearRegression

Explaining the algorithm :

The code first imports the numpy and sklearn.linear_model modules. Then, it creates the input data and target values. The input data is a NumPy array with four rows and two columns. The target values are a NumPy array with four elements.

Next, the code creates a linear regression model object. The LinearRegression() class takes a number of parameters, but the default values are usually fine.

The code then fits the linear regression model to the data using the fit() method. The fit() method takes two arguments: the input data and the target values.

Once the model is fitted, the code makes predictions using the predict() method. The predict() method takes a single argument: the input data. The predict() method will return the predicted values for the input data.

Finally, the code prints the predictions. The predictions are a NumPy array with four elements.

The code works by fitting a line to the data. The line is represented by a mathematical equation of the form y = mx + b, where m is the slope of the line and b is the y-intercept. The fit() method finds the values of m and b that minimize the error between the predicted values and the actual target values.

The predict() method uses the values of m and b to predict the values of y for a new set of input data.

The output of the code is a NumPy array with four elements. The elements of the array are the predicted values for the input data.