train_predict = model.predict(X_train) test_predict = model.predict(X_test) train_predict = scaler.inverse_transform(train_predict) y_train = scaler.inverse_transform([y_train]) train_predict = np.tile(train_predict, (1, 4)) #将train_predict复制4次,变为(110,4) train_predict = scaler.inverse_transform(train_predict) #进行逆归一化操作 y_train = np.tile(y_train, (1, 4)) #将y_train复制4次,变为(1, 440) y_train = scaler.inverse_transform(y_train.T) #进行逆归一化操作,并将结果reshape为(110,4) test_predict = scaler.inverse_transform(test_predict) y_test = scaler.inverse_transform([y_test])报错Traceback (most recent call last): File "C:\Users\马斌\Desktop\cnn测试\cnn改.py", line 47, in <module> train_predict = scaler.inverse_transform(train_predict) File "D:\python\python3.9.5\pythonProject\venv\lib\site-packages\sklearn\preprocessing_data.py", line 541, in inverse_transform X -= self.min_ ValueError: non-broadcastable output operand with shape (110,1) doesn't match the broadcast shape (110,4)如何修改代码
时间: 2023-12-24 08:09:16 浏览: 137
ML神器:sklearn的快速使用及入门
你需要将y_train的形状变为(110,4),可以使用numpy的reshape()函数。具体修改代码如下:
```
train_predict = model.predict(X_train)
test_predict = model.predict(X_test)
train_predict = scaler.inverse_transform(train_predict)
y_train = scaler.inverse_transform([y_train])
train_predict = np.tile(train_predict, (1, 4)) #将train_predict复制4次,变为(110,4)
train_predict = scaler.inverse_transform(train_predict) #进行逆归一化操作
y_train = np.tile(y_train, (1, 4)) #将y_train复制4次,变为(1, 440)
y_train = scaler.inverse_transform(y_train.T) #进行逆归一化操作,并将结果reshape为(110,4)
y_train = y_train.reshape(110, 4)
test_predict = scaler.inverse_transform(test_predict)
y_test = scaler.inverse_transform([y_test])
```
这样修改后,y_train的形状就变为了(110,4),可以进行逆归一化操作了。
阅读全文