OneCompiler

multivariate

138

import pandas as pd
import matplotlib.pyplot as plt
df=pd.read_csv('Advertising.csv')
df.head()
X=df[['TV','Radio','Newspaper']].values
y=df['Sales'].values
from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.3,random_state=100)
from sklearn.linear_model import LinearRegression
mlr=LinearRegression()
mlr.fit(X_train,y_train)
y_pred_mlr=mlr.predict(X_test)
print("Intercepts: ",mlr.intercept_)
print('Coefficients: ')
list(zip(X,mlr.coef_))
mlr_df=pd.DataFrame({'Actual Values': y_test,'Predicted Values':y_pred_mlr})
mlr_df.head()
from sklearn import metrics
import numpy as np
print(f'Mean Absolute Error:{metrics.mean_absolute_error(y_test,y_pred_mlr):.3f} ')
print(f'Mean Squared Error:{metrics.mean_squared_error(y_test,y_pred_mlr):.3f} ')
print(f'Root Mean Squared Error:{np.sqrt(metrics.mean_squared_error(y_test,y_pred_mlr)):.3f} ')