Python Forum
Found input variables with inconsistent numbers of samples: [1000, 200]
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Found input variables with inconsistent numbers of samples: [1000, 200]
#1
Hi all,
I have this code that compiles all the way to the end. Once the function returns it goes though some accuracy calculations that are not set by me and hence I cannot really debug it. Though it might be something in my code.
        
        # Encoding categorical data in y
        labelencoder_y = LabelEncoder()
        y = labelencoder_y.fit_transform(y)

        self.X_train, self.X_test, self.y_train, self.y_test = train_test_split(X, y, test_size=0.2, random_state = 40)

        sc = StandardScaler()
        self.X_train = sc.fit_transform(self.X_train)
        self.X_test = sc.transform(self.X_test)
         

        # Fit to the training data
        self.clf.fit(self.X_train, self.y_train)
        
        y_pred = self.clf.predict(self.X_test)
        print(accuracy_score(self.y_test, y_pred))
        result = np.array(y_pred, dtype=bool)
        #resulti = resulti.reshape((200,1))
        result
        print("result")
        print(result.shape)
        print('ypred')
        print(y_pred.shape)
        print('y_train')
        print(self.y_train.shape)
        print('X_train')
        print(self.X_train.shape)
        print("WE ARE DONE")
return result
result shape is
(200,)
ypred shape is
(200,)
y_train shape is
(800,)
X_train shape is
(800, 61)
WE ARE DONE
And the code throws the error as Found input variables with inconsistent numbers of samples: [1000, 200] where my result variable is of shape (200,). Though my datataframe is of size 1000x13. Any suggestions? THanks
Jenya
Reply
#2
Hi Jenya56, you are not making it easy for us to understand the problem. First: if there is an error message you should post the complete message (in error tags). Second: the code you show us appears to generate no errors, but you mention vaguely there are accuracy calculations running after your code. Apperantly the error comes from those calculations.
You mention:
(Sep-14-2021, 09:11 PM)jenya56 Wrote: Once the function returns
... but there is no function in your code, and then of course no return statement. My guess is you should write this as a function, returning values to the accuracy calculations.
Reply
#3
(Sep-15-2021, 09:48 AM)ibreeden Wrote: Hi Jenya56, you are not making it easy for us to understand the problem. First: if there is an error message you should post the complete message (in error tags). Second: the code you show us appears to generate no errors, but you mention vaguely there are accuracy calculations running after your code. Apperantly the error comes from those calculations.
You mention:
(Sep-14-2021, 09:11 PM)jenya56 Wrote: Once the function returns
... but there is no function in your code, and then of course no return statement. My guess is you should write this as a function, returning values to the accuracy calculations.

Hi! I actually found the problem. For reference, I did not have to do splitting of data. My y_pred was not equal to y (shape wise) and was complaining about that! THANK YOU
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Inconsistent counting / timing with threading rantwhy 1 164 Nov-24-2021, 04:04 AM
Last Post: deanhystad
  Inconsistent behaviour in output - web scraping Steve 6 472 Sep-20-2021, 01:54 AM
Last Post: Larz60+
  Packages inconsistent warning during hdbscan install Led_Zeppelin 0 357 Aug-31-2021, 04:10 PM
Last Post: Led_Zeppelin
  Python Pandas: How do I average ONLY the data >1000 from several columns? JaneTan 0 515 Jul-17-2021, 01:34 PM
Last Post: JaneTan
  Python Pandas: How do I extract all the >1000 data from a certain column? JaneTan 0 454 Jul-17-2021, 09:09 AM
Last Post: JaneTan
  How can I found how many numbers are there in a Collatz Sequence that I found? cananb 2 960 Nov-23-2020, 05:15 PM
Last Post: cananb
  How do I calculate a ratio from 2 numbers and return an equivalent list of about 1000 Pleiades 6 7,589 Jul-01-2020, 03:53 PM
Last Post: ndc85430
  square root of 5 input numbers mrityunjoy 1 818 Jun-10-2020, 11:08 AM
Last Post: perfringo
  square root of 6 input numbers mrityunjoy 3 1,117 Jun-07-2020, 06:35 AM
Last Post: ndc85430
  inconsistent map() behavior mcmxl22 2 1,058 May-23-2020, 10:17 PM
Last Post: mcmxl22

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020