import seaborn as sns
import pandas as pd
import numpy as nm
import matplotlib.pyplot as plt


from sklearn.linear_model import LinearRegression 

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=42)

ValueError                                Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_5388\1414350166.py in <module>
----> 1 X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)

~\Anaconda3\envs\MACHINELEARNING\lib\site-packages\sklearn\model_selection\_split.py in train_test_split(test_size, train_size, random_state, shuffle, stratify, *arrays)
   2415         raise ValueError("At least one array required as input")
-> 2417     arrays = indexable(*arrays)
   2419     n_samples = _num_samples(arrays[0])

~\Anaconda3\envs\MACHINELEARNING\lib\site-packages\sklearn\utils\validation.py in indexable(*iterables)
    377     result = [_make_indexable(X) for X in iterables]
--> 378     check_consistent_length(*result)
    379     return result

~\Anaconda3\envs\MACHINELEARNING\lib\site-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         )

ValueError: Found input variables with inconsistent numbers of samples: [53940, 1064]
  • 1
    $\begingroup$ This example references a variable X which is not defined. (The variable x is defined, but Python is case sensitive.) Is this a typo, or is the variable X defined somewhere? (If you're using jupyter, you may want to press "Restart Kernel" to make sure there are not any variables hanging around from previous versions of this code.) $\endgroup$
    – Nick ODell
    Commented May 21, 2023 at 22:54
  • $\begingroup$ Thanks Nick ODell you are right. X was not defined properly. $\endgroup$
    – brijesh
    Commented May 22, 2023 at 17:08

2 Answers 2


In addition to what Nick ODell pointed out in the comments about X not being defined, the ValueError you're seeing is because you are calling train_test_split on two different sized arrays. Your X and y inputs to train_test_split need to be the same sizes, here they are 53940 and 1064 respectively. In other words, for every input, you need exactly one output. hth.


Yes, please check xin x=df[['timepoint','subject']] versus X in train_test_split(X...



This should be

df=pd.read_csv('fmri') # but I don't know the format for this data set

Just be sure that the script is run from the same directory as fmri

A small example data set would be cool. You are using both sns and matplotlib for plotting, but ins will not load a data set thats pandas

  • $\begingroup$ Upvotes or acceptance is always preferred to thanks @brijesh $\endgroup$
    – M__
    Commented May 22, 2023 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.