Skip to content
Advertisement

How to perform scikit learn’s test-train split for a 2D input?

This is a beginner level question on scikit learn’s test-train split module.

I am working trying to feed in 2 inputs to the input layer of my neural network, but I am not able to get the input matrix’s dimensions correct! What change I should implement to get this working!

X1 and X2 are my inputs and y is my output. e.g. I wish to input X1 = 3.14 and X2 = -1.0 and my y should be equal to 0.0 . This way I want to train my network.

As of now I am getting an error saying:

ValueError: Found input variables with inconsistent numbers of samples: [2, 126]

Code:

JavaScript

For my network I will further build on a deep NN using keras, which will follow further code from here on.

JavaScript

Advertisement

Answer

Your X1 and X2 are not vectors X1.shape – (126,)

When you created array X, you added two lists in two rows and got (2,126) shape.

but you need input X shape – (126,2), you features should be in columns.

first column X1, second column X2

You can simple transpose X array in your case, use this line instead:

JavaScript
Advertisement