'Found input variables with inconsistent numbers of samples: [301056, 253]

I am working on ML and for training my data, I used these functions.

What I already did in this:

I already apply replacing the value of X in it.

Code:

from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(X, data_target, test_size = 0.1, random_state = 3) 

Error shown below the code:

ValueError                                Traceback (most recent call last)
<ipython-input-37-f5111ea343c6> in <module>()
      1 from sklearn.model_selection import train_test_split
----> 2 x_train, x_test, y_train, y_test = train_test_split(X, data_target, test_size = 0.1, random_state = 3)

2 frames
/usr/local/lib/python3.7/dist-packages/sklearn/utils/validation.py in check_consistent_length(*arrays)
    332         raise ValueError(
    333             "Found input variables with inconsistent numbers of samples: %r"
--> 334             % [int(l) for l in lengths]
    335         )
    336 

ValueError: Found input variables with inconsistent numbers of samples: [301056, 253]

Error: Found input variables with inconsistent numbers of samples: [301056, 253]

enter image description here

I did replacing the X in it!



Solution 1:[1]

You are getting this error because number of rows in X not the same in data_target. They should be equal.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 skon7