Sidharth kaushik
Sidharth kaushik

Reputation: 257

Multiple Linear Regression 100% Accuracy

I am getting 100% accuracy in multiple linear regression. I am following one tutorial of last year. He is not getting 100% accuracy on the same model but I am getting now. Seems weird to me. Here's my code. Am I am doing it right or there's something wrong in my code?

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd


dataset = pd.read_csv('M_Regression.csv')
X = dataset.iloc[:, :-1].values
Y = dataset.iloc[:, :1].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=0)

#regression
from sklearn.linear_model import LinearRegression
reg = LinearRegression()
reg.fit(X_train,Y_train)

#Prediction
y_pred = reg.predict(x_test)

print(str(y_test) + " - " + str(y_pred))

Upvotes: 1

Views: 1444

Answers (2)

Sidharth kaushik
Sidharth kaushik

Reputation: 257

Linear Regression have simple numbers it is common to have 100% accuracy on large dataset. Try with other datasets once. I tried your code i got 1.0 Accuracy on it.

Upvotes: 1

NHL
NHL

Reputation: 287

To check the accuracy of your model, you could try printing the r2 score of your test sample. Something among the lines of :

from sklearn.metrics import r2_score
print(r2_score(y_test,y_pred))

if you still have issues with the score. You could try removing the "random_state=0" to check if you still have 100% accuracy with several train/test data sets.

Upvotes: 2

Related Questions