title: Typerror (Singleton array...) when using train_test_split within a custom class
body: <blockquote>
  <p>TypeError: Singleton array array(&lt;__main__.AZHU_EmailClassifier_2
  object at 0x000001D6E7A680D0&gt;, dtype=object) cannot be considered a
  valid collection.</p>
  </blockquote>
  <p>I get this error when I try to run the train_test_split function within my custom AZHU_EmailClassifier_2 class.</p>
  <p>My class:</p>
  <pre><code>class AZHU_EmailClassifier_2:
      import os
      import numpy as np
      import pandas as pd
      from sklearn.model_selection import train_test_split
  
      def __init__(self):
          pass
      
      def retrain_model(self, csv_file):
          
          MIN_ROW_NUMBER = 500
          TEST_SIZE = 0.25
          RANDOM_STATE = 42
          
          self.os.chdir(r&quot;c:\LORI\PROJECTS\ALLIANZ\INCOMING_CHANNELS&quot;) # &lt;---- a retraining file mappaja
          
          df=self.pd.read_excel(csv_file,error_bad_lines=False, header=None)
          
          df.dropna(axis=0,how='any', inplace=True)
               
          rows_no=df.shape[0]
          if rows_no&lt;MIN_ROW_NUMBER:
              print(&quot;Insufficient number of rows (&lt;35.000)! RETRAINING ABORTED&quot;)
              return None
  
          X=df[0]
          y=df[1]
          
          X_train, X_test, y_train, y_test=self.train_test_split(X,y)
          #X_train, X_test, y_train, y_test=self.train_test_split(X,y,test_size=TEST_SIZE, random_state=RANDOM_STATE, stratify=y)
          
          return X_train
                  
  </code></pre>
  <p>The error is triggered when I run the train_test_split function.</p>
  <p>The whole error message:</p>
  <blockquote>
  <p>--------------------------------------------------------------------------- TypeError                                 Traceback (most recent call
  last)  in 
  1 instance = AZHU_EmailClassifier_2()
  2
  ----&gt; 3 instance.retrain_model(&quot;retraining_dummy.xlsx&quot;)</p>
  <p> in retrain_model(self, csv_file)
  28         y=df[1]
  29
  ---&gt; 30         X_train, X_test, y_train, y_test=self.train_test_split(X,y)
  31         #X_train, X_test, y_train, y_test=self.train_test_split(X,y,test_size=TEST_SIZE,
  random_state=RANDOM_STATE, stratify=y)
  32</p>
  <p>~\Anaconda3\lib\site-packages\sklearn\model_selection_split.py in
  train_test_split(*arrays, **options)    2125         raise
  TypeError(&quot;Invalid parameters passed: %s&quot; % str(options))    2126
  -&gt; 2127     arrays = indexable(*arrays)    2128     2129     n_samples = _num_samples(arrays[0])</p>
  <p>~\Anaconda3\lib\site-packages\sklearn\utils\validation.py in
  indexable(*iterables)
  291     &quot;&quot;&quot;
  292     result = [_make_indexable(X) for X in iterables]
  --&gt; 293     check_consistent_length(*result)
  294     return result
  295</p>
  <p>~\Anaconda3\lib\site-packages\sklearn\utils\validation.py in
  check_consistent_length(*arrays)
  251     &quot;&quot;&quot;
  252
  --&gt; 253     lengths = [_num_samples(X) for X in arrays if X is not None]
  254     uniques = np.unique(lengths)
  255     if len(uniques) &gt; 1:</p>
  <p>~\Anaconda3\lib\site-packages\sklearn\utils\validation.py in
  (.0)
  251     &quot;&quot;&quot;
  252
  --&gt; 253     lengths = [_num_samples(X) for X in arrays if X is not None]
  254     uniques = np.unique(lengths)
  255     if len(uniques) &gt; 1:</p>
  <p>~\Anaconda3\lib\site-packages\sklearn\utils\validation.py in
  _num_samples(x)
  194     if hasattr(x, 'shape') and x.shape is not None:
  195         if len(x.shape) == 0:
  --&gt; 196             raise TypeError(&quot;Singleton array %r cannot be considered&quot;
  197                             &quot; a valid collection.&quot; % x)
  198         # Check that shape is returning an integer or default to len</p>
  <p>TypeError: Singleton array array(&lt;<strong>main</strong>.AZHU_EmailClassifier_2
  object at 0x000001D6E7A68F10&gt;,
  dtype=object) cannot be considered a valid collection.</p>
  </blockquote>
  <p>I have no clue why does it throw this error. Could you please point me in the right direction? Any help is appreciated!</p>