HOW TO SOLVE - Found input variables with inconsistent numbers of samples 2285 762 ERROR

0 votes

import pandas as pd
import numpy as np

df = pd.read_csv("cancer_reg.csv", sep=',', encoding='gbk')

df=df.drop(["Geography"],axis=1)
df=df.drop(["binnedInc"],axis=1)


df['PctSomeCol18_24'].fillna(df['PctSomeCol18_24'].mean(), inplace=True) 
df['PctEmployed16_Over'].fillna(df['PctEmployed16_Over'].mean(), inplace=True) 
df['PctPrivateCoverageAlone'].fillna(df['PctPrivateCoverageAlone'].mean(), inplace=True) 

X=df.iloc[:, df.columns != "TARGET_deathRate"].values
y=df.loc[:,"TARGET_deathRate"].values

y.reshape(-1,1)

X.shape

from sklearn.model_selection import train_test_split
X_train,y_train,X_test,y_test=train_test_split(X,y , test_size=0.25, random_state=0)

from sklearn.preprocessing import StandardScaler
scaler=StandardScaler()

scaler.fit(X_train)
X_train = scaler.transform(X_train)
X_test = scaler.fit_transform(X_test)

scaler.fit(y_train)
y_train = scaler.transform(y_train)
y_test = scaler.fit_transform(y_test)

from sklearn.linear_model import LinearRegression
lr=LinearRegression()

lr.fit(X_train,y_train)

ValueError: Found input variables with inconsistent numbers of samples: [2285, 762]

how to solve this error

Mar 19, 2021 in Python by Manu

edited Mar 4 18 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP