sklearn.preprocessing.MinMaxScaler:不可广播的输出形状错误

时间:2019-06-10 13:06:32

标签: python scikit-learn preprocessor inverse-transform

任何人都可以解释我为什么会出现以下错误:

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

执行时:

    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 = f(X) #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 = f(p) #np.shape(p) is (1, 1)

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

我真的不明白为什么将inverse_transform应用于尺寸不同于X的f(X)的结果,一切都很好,而对尺寸不同于p的f(p)进行相同处理却得到了错误。

0 个答案:

没有答案