0
$\begingroup$

Screenshot of codesData source

I received that error and when running my code, I realised that the issue lies with my X_train and y_train.

The link below is the source of my data (test.csv and train.csv)

My X_train.shape gave me (15573,) and my y_train gave me (15600,)

How do I reshape this?

$\endgroup$
  • $\begingroup$ You cat reshap them, you have to figure why it's happening because y_train and X_train will have same shape by default $\endgroup$ – Aditya Apr 8 '19 at 5:34
  • $\begingroup$ @Aditya Strangely, my X_test and y_test tally...Is there a particular reason why it isn't the same for y_train and X_train? $\endgroup$ – Renae Apr 8 '19 at 5:54
  • $\begingroup$ See if you are dropping some rows or not or else if they are one-to-one matching, then just reduce the X_train; $\endgroup$ – Aditya Apr 8 '19 at 5:59
  • $\begingroup$ @Aditya Got it, will give that a shot! To reduce the X_train, I inputted this code: y_train_new=y_train[1:17644] but it showed me an error. The aim is to make it the same as that of y_train $\endgroup$ – Renae Apr 8 '19 at 6:13
  • $\begingroup$ 17644 isn't the y_train dims, it's 15600 but be careful, you shouldn't be using such tricks as in a normal scenario, this shouldn't happen actually. If you can share your preprocessing, folks can then help finding what's causing it unless it's by default like that $\endgroup$ – Aditya Apr 8 '19 at 6:33
1
$\begingroup$

You likely get problems because you remove rows containing nulls in X_train and y_train independent of each other. y_train probably has few, or no nulls and X_train probably has some. So when you remove a row in X_train and the same row is not removed in y_train it will cause your data to be unsynced and have different lenghts. Instead you should remove nulls before you separate X and y.

Before this:

X = df['text']
y = df['label']

Do this:

df.dropna(inplace=True)

And remove this:

X_train.dropna(inplace=True)
X_test.dropna(inplace=True)
y_train.dropna(inplace=True)
y_test.dropna(inplace=True)
$\endgroup$
  • $\begingroup$ That worked! Thank you :) $\endgroup$ – Renae Apr 9 '19 at 9:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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