Когда я пытаюсь оптимизировать LSTM с помощью тюнера keras в Python, я получаю следующую ошибку: AttributeError: модуль «keras.src.activations» не имеет атрибута «get».
Я использую следующие версии: | Версия Python: 3.11.7 | Версия Кераса: 3.4.1 | Версия TensorFlow: 2.16.2 | Версия Keras Tuner: 1.0.5
#LOADING REQUIRED PACKAGES
import pandas as pd
import math
import keras
import numpy as np
from sklearn.preprocessing import MinMaxScaler
from tensorflow.keras.models import save_model
from tensorflow.keras.models import model_from_json
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
from tensorflow.keras.layers import LSTM
from tensorflow.keras.layers import Dropout
from kerastuner.tuners import RandomSearch
from kerastuner.engine.hyperparameters import HyperParameters
#GENERATING SAMPLE DATA
# Creating x_train_data with 300 observations and 10 columns
x_train_data = pd.DataFrame(np.random.rand(300, 10))
# Creating y_train_data with 300 observations and 1 column
y_train_data = pd.DataFrame(np.random.rand(300, 1))
# Creating x_test_data with 10 observations and 10 columns
x_test_data = pd.DataFrame(np.random.rand(10, 10))
# Creating y_test_data with 10 observations and 1 column
y_test_data = pd.DataFrame(np.random.rand(10, 1))
#RESHAPING DATA
nrow_xtrain, ncol_xtrain = x_train_data.shape
x_train_data_lstm = x_train_data.reshape(1,nrow_xtrain, ncol_xtrain)
nrow_ytrain= y_train_data.shape[0]
y_train_data_lstm = y_train_data.reshape(1,nrow_ytrain,1)
nrow_ytest= y_test.shape[0]
y_test_data_lstm = y_test.reshape(1,nrow_ytest,1)
nrow_xtest, ncol_xtest = X_test.shape
x_test_data_lstm = X_test.reshape(1,nrow_xtest, ncol_xtest)
#BUILDING AND ESTIMATING MODEL
def build_model(hp):
model = Sequential()
model.add(LSTM(hp.Int('input_unit',min_value=1,max_value=512,step=32),return_sequences=True, input_shape=(x_train_data_lstm.shape[1],x_train_data_lstm.shape[2])))
for i in range(hp.Int('n_layers', 1, 4)):
model.add(LSTM(hp.Int(f'lstm_{i}_units',min_value=1,max_value=512,step=32),return_sequences=True))
model.add(LSTM(hp.Int('layer_2_neurons',min_value=1,max_value=512,step=32)))
model.add(Dropout(hp.Float('Dropout_rate',min_value=0,max_value=0.5,step=0.1)))
model.add(Dense(10, activation=hp.Choice('dense_activation',values=['relu', 'sigmoid',"linear"],default='relu')))
model.compile(loss='mean_squared_error', optimizer='adam',metrics = ['mse'])
return model
tuner= RandomSearch(
build_model,
objective='mse',
max_trials=2,
executions_per_trial=1
)
tuner.search(
x=X_train,
y=Y_train,
epochs=20,
batch_size=128,
validation_data=(x_test_data_lstm,y_test_data_lstm),
)
Подробнее здесь: https://stackoverflow.com/questions/787 ... ribute-get
AttributeError: модуль «keras.src.activations» не имеет атрибута «get». ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
AttributeError: модуль «keras.src.activations» не имеет атрибута «get».
Anonymous » » в форуме Python - 0 Ответы
- 20 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Dipy — ошибка атрибута: AttributeError: модуль «numpy» не имеет атрибута «float»
Anonymous » » в форуме Python - 0 Ответы
- 27 Просмотры
-
Последнее сообщение Anonymous
-