当我运行代码时,我得到了附图所示的错误。我该如何克服这个错误?该代码是 ANN 分析代码的前部。它给出了 R2 和 RMSE 值作为结果,但我
当我运行代码时,出现附图所示的错误。
我该如何克服这个错误?该代码是 ANN 分析代码的前部。它给出了 R2 和 RMSE 值作为结果,但我怀疑我做错了什么。我写的如下:
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import r2_score, mean_squared_error
import tensorflow as tf
from tensorflow.models import Sequential
from tensorflow.layers import Dense, BatchNormalization, Dropout
from tensorflow.callbacks import ModelCheckpoint, EarlyStopping, ReduceLROnPlateau
from tensorflow.optimizers import Adam
您可以尝试两种方法来解决这个问题。第一种方法是通过 TensorFlow 正确导入 keras。如果您正在使用 tensorflow,这是最好的方法。
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import r2_score, mean_squared_error
import tensorflow as tf
from tensorflow.python.keras.models import Sequential
from tensorflow.python.keras.layers import Dense, BatchNormalization, Dropout
from tensorflow.python.keras.callbacks import ModelCheckpoint, EarlyStopping, ReduceLROnPlateau
from tensorflow.python.keras.optimizers import Adam
另外,你可以直接从 Keras 库导入。如果你在后端工作,你应该尝试这种方法。
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import r2_score, mean_squared_error
import tensorflow as tf
from keras.models import Sequential
from keras.layers import Dense, BatchNormalization, Dropout
from keras.callbacks import ModelCheckpoint, EarlyStopping, ReduceLROnPlateau
from keras.optimizers import Adam