ValueError: Found input variables with inconsistent numbers of samples: [1319, 245]

We Are Going To Discuss About ValueError: Found input variables with inconsistent numbers of samples: [1319, 245]. So lets Start this Python Article.

ValueError: Found input variables with inconsistent numbers of samples: [1319, 245]

  1. How to solve ValueError: Found input variables with inconsistent numbers of samples: [1319, 245]

    Check the shape of both X and y. It must have same number of rows.
    print(X.shape) print(y.shape) if X.shape[0] != y.shape[0]: print("X and y rows are mismatched, check dataset again")
    Note:
    The rows of both X and y should be same
    You have used dataset for X whereas dataset1 for y which should be the main error in your code.
    See here:
    X = dataset[:,0:2] y = dataset1[:,2]
    dataset and dataset1 are two different dataframes which might represent two different data.

  2. ValueError: Found input variables with inconsistent numbers of samples: [1319, 245]

    Check the shape of both X and y. It must have same number of rows.
    print(X.shape) print(y.shape) if X.shape[0] != y.shape[0]: print("X and y rows are mismatched, check dataset again")
    Note:
    The rows of both X and y should be same
    You have used dataset for X whereas dataset1 for y which should be the main error in your code.
    See here:
    X = dataset[:,0:2] y = dataset1[:,2]
    dataset and dataset1 are two different dataframes which might represent two different data.

Solution 1

Check the shape of both X and y. It must have same number of rows.

print(X.shape)
print(y.shape)

if X.shape[0] != y.shape[0]:
  print("X and y rows are mismatched, check dataset again")

Note:

  • The rows of both X and y should be same

You have used dataset for X whereas dataset1 for y which should be the main error in your code.

See here:

X = dataset[:,0:2]
y = dataset1[:,2]

dataset and dataset1 are two different dataframes which might represent two different data.

Original Author Prakash Dahal Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

ittutorial team

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment