<jupyter_start><jupyter_text>Assignment 01: Evaluate the Ad Budget Dataset of XYZ FirmAnalysing Ad Budgets for different media channelsProblem:The given dataset contains ad budgets for different media channels and the corresponding ad sales of XYZ firm. Evaluate the dataset to:    Find the features or media channels used by the firm    Find the sales figures for each channel    Create a model  to predict the sales outcome    Split as training and testing datasets for the model    Calculate the Mean Square Error (MSE)* * *  1: Import the dataset<jupyter_code>#Import the required libraries
import pandas as pd
#Import the advertising dataset
df_ad_datasetRaw = pd.read_csv("Advertising_Budget_and_Sales.csv", index_col=0)<jupyter_output><empty_output><jupyter_text>2: Analyze the dataset<jupyter_code>#View the initial few records of the dataset
df_ad_datasetRaw.head()
#Check the total number of elements in the dataset
df_ad_datasetRaw.size<jupyter_output><empty_output><jupyter_text>3: Find the features or media channels used by the firm<jupyter_code>#Check the number of observations (rows) and attributes (columns) in the dataset
df_ad_datasetRaw.shape
#View the names of each of the attributes
df_ad_datasetRaw.columns<jupyter_output><empty_output><jupyter_text>4: Create objects to train and test the model; find the sales figures for each channel<jupyter_code>df_ad_datasetRaw
#Create a feature object from the columns
x_feature = df_ad_datasetRaw[['TV','Radio','Newspaper']]
#View the feature object
x_feature.head()
#Create a target object (Hint: use the sales column as it is the response of the dataset)
y_feature = df_ad_datasetRaw[['Sales']]
#View the target object
y_feature.head()
#Verify if all the observations have been captured in the feature object
x_feature.shape
#Verify if all the observations have been captured in the target object
y_feature.shape<jupyter_output><empty_output><jupyter_text>5: Split the original dataset into training and testing datasets for the model<jupyter_code>#Split the dataset (by default, 75% is the training data and 25% is the testing data)
from sklearn.model_selection import train_test_split
#Verify if the training and testing datasets are split correctly (Hint: use the shape() method)
x_train, x_test, y_train, y_test = train_test_split(x_feature,y_feature,random_state=1)
#print the train and test data shape
print(x_train.shape)
print(y_train.shape)
print(x_test.shape)
print(y_test.shape)<jupyter_output>(150, 3)
(150, 1)
(50, 3)
(50, 1)<jupyter_text>6: Create a model  to predict the sales outcome<jupyter_code>#Create a linear regression model
from sklearn.linear_model import LinearRegression
linreg = LinearRegression()
linreg.fit(x_train,y_train)
#Print the intercept and coefficients 
print(linreg.intercept_)
print(linreg.coef_)
#Predict the outcome for the testing dataset
y_pred = linreg.predict(x_test)
y_pred<jupyter_output><empty_output><jupyter_text>7: Calculate the Mean Square Error (MSE)<jupyter_code>#Import required libraries for calculating MSE (mean square error)
from sklearn import metrics
import numpy as np
#Calculate the MSE
print (np.sqrt(metrics.mean_squared_error(y_test,y_pred)))<jupyter_output>1.4046514230328953
{'fraction_non_alphanumeric': 0.067601246105919, 'fraction_numerical': 0.014330218068535825, 'mean_word_length': 6.8508557457212715, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '569612', 'license': 'MIT', 'n_tokens_mistral': 1011, 'n_tokens_neox': 960, 'n_words': 358, 'path': 'assignments/Lesson_8_ML_basics/Assignment_Advertising_Budget_and_Sales.ipynb', 'repo_name': 'kdeepakkumarbk/DataSci_WithPy_DPK', 'size': '3210'}