I am trying to do a multiple linear regression in python but I am getting different result in python and when i do it in excel here is my code. Please help me out. Dataset
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error, r2_score
# Load your dataset (replace 'your_dataset.csv' with your actual dataset)
df = pd.read_csv('your_dataset.csv')
# Define the dependent and independent variables
Y = df.iloc[:, 0] # Column 1 as the dependent variable
X = df.iloc[:, 1:6] # Columns 2 to 6 as independent variables
# Split the data into training and testing sets
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2, random_state=0)
# Create a linear regression model
model = LinearRegression()
# Fit the model to the training data
model.fit(X_train, Y_train)
# Make predictions on the test data
Y_pred = model.predict(X_test)
# Evaluate the model
mse = mean_squared_error(Y_test, Y_pred)
r2 = r2_score(Y_test, Y_pred)
print("Mean Squared Error:", mse)
print("R-squared:", r2)
# Coefficients and intercept
coefficients = model.coef_
intercept = model.intercept_
print("Coefficients:", coefficients)
print("Intercept:", intercept)
Why is there a difference in both the values