0
$\begingroup$

Why I am getting the following error:

ValueError: non-broadcastable output operand with shape (1,1) 
  doesn't match the broadcast shape (1,2)

While executing:

X = np.array([[i, j] for i, j in zip(dati['a'], dati['b'])], 
    dtype = float) #np.shape(X) is (23, 2)

scaler = MinMaxScaler(feature_range=(0, 1))
X = scaler.fit_transform(X) #np.shape(X) is (23, 2)

X = np.reshape(X, (X.shape[0], X.shape[1], 1)) #np.shape(X) is (23, 2, 1)

X = scaler.inverse_transform(nn.predict(X, batch_size = batch_size)) #np.shape(X) is (23, 1)

X = scaler.inverse_transform(X)

p = np.array([dati[['a','b']].iloc[-1]], dtype = float) #np.shape(X) is (1, 2)

scaler = MinMaxScaler(feature_range=(0, 1))
p = scaler.fit_transform(p) #np.shape(X) is (1, 2)

p = np.reshape(p, (p.shape[0], p.shape[1], 1)) #np.shape(X) is (1, 2, 1)

p = scaler.inverse_transform(nn.predict(p, batch_size = batch_size)) #np.shape(p) is (1, 1)

p = scaler.inverse_transform(p) #Here the error

I really do not understand why applying the inverse_transform on the result of nn.predict(X), which has different dimensions than X, is fine, while doing the same on the result of nn.predict(p), which has different dimensions than p, causes an error.

$\endgroup$
0
$\begingroup$

The min max scaler I am assuming in the second case because there is only 1 row the columns as its values it has to scale and learnt it min and Max from it. Hence when you pass only 1 value it's complaining.

In the 23x2 table above it didn't have this problem because it was learning the scaler columnwise.

The second example doesn't make any sense either because for 1 example min == max and hence your value would not be between 0 and 1.

$\endgroup$
0
$\begingroup$

This looks pretty complicated ... I might start very simple:

Did you try to scale X without batch/transform?

enter image description here

$\endgroup$
  • $\begingroup$ FNo I didn’t tried to scale X without fit_transform. But the problem is not X. Everything is fine scaling X and using it to train the NN. The problem arise when I scale P which is a value that needs to be processed by the NN after its training (what interest me is the result giving P as input which is a prediction) - please note that the NN has been trained with scaled values of X so P also must be scaled. The processing of P results in a scaled result which need to be reversed - that’s why I’m using a transformation function (it can be reversed). $\endgroup$ – Nipper Jun 13 at 0:37

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.