CNN 帮助(非常新)

问题描述 投票:0回答:1

我正在制作一个深度学习模型来预测一个值。声明如下:我们有一个
时间 vs A vs B vs C - xls 文件(多个,存在于 Data 命名文件夹中)
我想使用 A、B、C 的先前值来预测 A。这意味着当它是第一个预测时,我们将得到 N/A,因为我们没有旧的 A 给用户。 目前我有这个:(我真的是新手,到处都在网上搜索):

def load_data(folder_path): data_frames = [] for file_name in os.listdir(folder_path): if file_name.endswith('.xls'): file_path = os.path.join(folder_path, file_name) df = pd.read_excel(file_path) # Assuming the data is in Excel format data_frames.append(df) return pd.concat(data_frames, ignore_index=True) def preprocess_data(data): X = data[['S', 'A', 'T']] y = data['F'] scaler = StandardScaler() X_scaled = scaler.fit_transform(X) X_reshaped = X_scaled.reshape(X_scaled.shape[0], X_scaled.shape[1], 1) # Reshape for CNN return X_reshaped, y, scaler def build_cnn_model(input_shape): model = Sequential() model.add(Conv1D(filters=1, kernel_size=10, activation='relu', input_shape=(1, 1,3),)) model.add(MaxPooling1D(pool_size=2)) model.add(Conv1D(filters=64, kernel_size=3, activation='relu')) model.add(MaxPooling1D(pool_size=2)) model.add(Flatten()) model.add(Dense(64, activation='relu')) model.add(Dense(1)) return model def train_and_predict_next_frequency(folder_path, current_scheduled, current_actual): data = load_data(folder_path) X, y, scaler = preprocess_data(data) X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) input_shape = (X_train.shape[1], 1) X_train_reshaped = X_train.reshape(X_train.shape[0], X_train.shape[1], 1) X_test_reshaped = X_test.reshape(X_test.shape[0], X_test.shape[1], 1) print(input_shape) model = build_cnn_model(input_shape) model.compile(optimizer='adam', loss='mean_squared_error') model.fit(X_train_reshaped, y_train, epochs=50, batch_size=32, verbose=1) mse = model.evaluate(X_test_reshaped, y_test, verbose=0) print("Mean Squared Error:", mse) scaled_input = scaler.transform([[current_scheduled, current_actual]]) input_reshaped = scaled_input.reshape(1, 2, 1) # Reshape for CNN next_frequency_scaled = model.predict(input_reshaped) next_frequency = scaler.inverse_transform(next_frequency_scaled.reshape(-1, 1)) return next_frequency[0][0] folder_path = "Data" # Folder containing the Excel files current_scheduled = 10 current_actual = 8 predicted_frequency = train_and_predict_next_frequency(folder_path, current_scheduled, current_actual) print("Predicted Next Frequency:", predicted_frequency)

我在这里收到此错误:ValueError:

One of the dimensions in the output is <= 0 due to downsampling in conv1d_10. Consider increasing the input size. Received input shape [None, 1, 1, 3] which would produce output shape with a zero or negative value in a dimension.

请帮忙。预先感谢,因为我知道这是一篇 LONGGG 帖子:(
使用

A、B、C
的先前值来预测 A。 (上一个是什么?,我们有时间来告诉)。 我尝试更改图层功能,但没有成功。我想实现上述目标

python deep-learning project ml
1个回答
0
投票
padding='same'

添加到

Conv1D
应该可以解决该错误。
model.add(Conv1D(filters=1, kernel_size=10, activation='relu', input_shape=(1, 1,3),padding='same'))

© www.soinside.com 2019 - 2024. All rights reserved.