Sales Prediction with Linear Regression
Sales Prediction with Linear Regression
Using multiple independent variables, such as TV, Radio, and Newspaper advertising, allows the linear regression model to capture the influence of various advertising mediums on sales. This multivariable approach can account for multiple factors affecting the outcome, providing a more comprehensive model that better predicts sales than single-variable models by capturing interactions and the combined effect of different ad spends.
The primary attributes used in the sales prediction model are TV, Radio, and Newspaper. These are represented as numerical features in the dataset after the 'Unnamed: 0' column is dropped. The 'Sales' column is considered the target variable. The dataset is split into attributes (X) and target variable (y) for model training, where X includes 'TV', 'Radio', and 'Newspaper'.
The model evaluates its performance using metrics such as Mean Absolute Error (MAE), Root Mean Square Error (RMSE), and R-Squared. MAE provides the average magnitude of the errors, RMSE measures the square root of the average of squared deviations, and R-Squared indicates how well the data fit's the regression model (with 82.84% accuracy)
Preparing the dataset for training involves reading the data into a pandas DataFrame, checking for null values or duplicates, and splitting the data into predictors (X) and the target variable (y). The train_test_split function from sklearn is used to divide the data into training and test sets. Further, libraries like pandas for data manipulation and sklearn for model operations facilitate this process.
The train_test_split function divides the dataset into training and testing sets, allowing the model to learn from a subset of data (80% of the total data) and validate its performance on unseen data (20% of the total data), ensuring the model’s reliability and generalizing ability.
Checking for duplicated entries helps ensure data quality and integrity by confirming that each data point is unique, which is crucial for reliable model training. In this analysis, a result of zero duplicated entries indicates a high-quality dataset without redundancy or duplication issues, ensuring that each observation contributes independently to the model.
Pandas facilitates data manipulation, including reading and inspecting the dataset to identify key statistics and features, handling data structures, and preprocessing. Matplotlib is used for visualizing relationships and trends within the data, facilitating scatter plots of sales against TV, Radio, and Newspaper advertising, allowing for a clearer understanding of potential correlations.
Scatterplot visualizations suggest a positive relationship between the amounts spent on TV and Radio advertising and Sales, indicating that investments in these mediums may significantly impact sales numbers. The scatterplot between Newspaper advertising and sales suggests a weaker correlation. Such visual insights help prioritize TV and Radio as more influential predictors in the sales model.
Mean Absolute Error (MAE) contributes by providing an average error magnitude in predictions without considering their direction. It is a straightforward metric indicating prediction accuracy, offering an average deviation of 1.42 units in sales prediction with this model—an understanding of typical prediction error magnitude.
The R-Squared value measures how well the independent variables explain the variance in the dependent variable, with values closer to 1 indicating a better fit. In this case, an R-Squared value of approximately 0.828 suggests that the advertising mediums collectively explain about 82.84% of the variance in sales, indicating a strong model performance.