@Argenum

Ошибка в питоне с библиотекой Nympy, как исправить?

import numpy as np
import keras as k
import tensorflow as tf
from keras.models import Sequential
from keras.layers import LSTM, Dense, Dropout
\------------------------\
train_x = np.array([-4.2,-7.1,-9.1,5.2,10.4,17.4,17.9,16.8,12.2,3.9,-1.2,-5.9,-10.4,-15.6,-2.6,7.2,11.6,19.2,19.0,17.3,10.0,5.8,-3.2,-5.6,-14.3,-14.0,-6.0,-1.8,-6.3,6.6,14.4,15.2,18.6,17.1,12.4,5.2,-0.9,-4.6,-7.0,-7.7,-6.0,4.1,13.3,14.9,18.4,15.7,9.1,6.0,-0.8,-7.6,-4.4,-5.5,-1.4,6.6,11.5,16.9,20.6,16.9,8.2,2.2,-5.1,-11.0,-9.4,-7.6,-5.5,5.0,11.6,18.5,21.0,16.2,9.8,2.3,-3.6,0.2,-6.2,-2.4,0.2,4.3,12.1,19.2,19.4,16.8,9.7,6.6,-1.6,-8.1,-4.2,-6.1,-5.0,7.6,13.2,13.5,16.4,14.8,10.8,6.4,1.4,-7.4,-15.9,-10.0,-9.4,3.9,17.0,13.5,19.1,17.8,13.2,5.6,-0.2,-8.8,-8.1,-10.0,-6.2,4.2,11.5,19.0,20.0,16.0,11.8,6.9,-2.3,-2.9,-9.6,-10.1,-3.3,2.5,9.7,16.0,16.7,15.8,12.9,3.8,-5.8,-1.5,-9.7,-8.9,0.0,8.7,15.4,16.5,19.2,16.6,9.5,6.1,-0.9,-10.5,-13.9,-10.4,0.3,6.0,12.4,18.3,15.7,17.7,10.8,3.0,-2.5,-5.3,-16.2,-13.4,-6.9,6.0,11.1,14.7,17.8,16.4,10.2,4.7,1.8,-9.2,-10.4,-8.3,-2.9,5.8,12.6,15.8,19.3,16.3,11.1,5.4,-1.8,-5.9,-3.5,-9.4,-4.2,3.8,12.8,16.4,17.5,16.7,10.8,3.2,-0.6,-5.7,-14.9,-7.4,-2.5,5.9,12.6,19.0,22.4,20.6,11.0,5.2,-0.2,-0.9,-10.2,-3.4,-1.0,7.9,13.3,18.2,18.0,15.9,7.6,3.8,-2.1,-5.9,-10.2,-1.5,-0.6,3.4,9.6,16.4,18.2,15.9,13.1,8.7,1.8,-2.3,-3.7,-6.4,1.2,10.1,15.6,17.8,18.5,15.0,13.7,4.1,-3.3,-4.0,-12.2,-11.4,-2.6,5.7,10.9,13.7,16.1,14.5,9.6,-1.0,-0.8,-3.7,-11.2,-6.3,-0.9,7.0,14.2,16.8,18.8,15.8,9.5,3.1,1.7,-8.2,-7.3,-9.5,0.4,4.6,10.5,14.3,16.3,15.8,9.7,3.3,2.0,-14.5,-9.9,-8.8,-0.9,3.3,17.1,17.2,16.7,16.9,11.7,3.8,-0.9,-5.7,-11.3,-7.1,-6.4,5.8,8.4,17.9,17.2,14.7,10.5,5.2,-2.0,-4.2,-5.4,-4.9,-3.1,3.3,14.0,19.8,21.5,17.4,10.8,7.8,-0.6,-3.5,-10.1,-8.8,-0.7,5.3,12.0,13.8,18.4,16.6,11.8,4.1,2.0,-1.1,-4.0,-6.9,-1.4,9.3,15.6,14.5,17.9,16.0,12.4,6.2,-1.5,-3.2,-4.4,-10.3,-2.3,7.5,16.0,15.6,17.6,15.1,12.4,6.8,-3.5,-9.6,-10.0,-14.0,-3.1,5.4,13.0,14.6,16.4,19.4,10.1,6.1,-3.3,-6.5,-6.7,-13.5,0.2,6.7,13.6,18.6,17.8,16.5,8.6,4.2,-0.1,-7.5,-17.5,-6.0,-5.3,2.8,12.8,17.7, 16.8,15.1,9.0,3.6,-3.6,-7.0,-7.2,-6.1,-1.0,5.3,13.8,19.5,21.6,16.5,11.3,4.9,-4.4,-6.9,-2.1,-0.5,2.0,7.7,13.4,20.0,19.2,16.2,12.2,5.3,-2.6,-5.3,-5.7,0.4,2.0,8.1,10.8,14.5,17.5,16.0,9.3,5.3,0.2,-3.4,-6.2,-6.7,-1.2,7.0,13.4,18.8,18.1,16.1,11.0,6.5,1.0,-4.0,-4.4,-10.3,-2.3,7.5,16.0,15.6,17.6,15.1,12.4,6.8,-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4,15.3,19.0,18.4,12.1,5.9,-1.6,-2.9,-3.0,-8.9,-6.0,7.1,14.8,16.5,19.3,17.6,13.1,6.0,1.4,-4.1,-10.8,-13.3,-3.7,6.0,12.4,18.2,18.0,17.5,13.3,7.0,0.7,1.2,-1.6,-11.0,4.4,5.8,15.9,17.4,18.9,20.2,11.8,7.0,-2.0,-2.0,-5.8,-1.5,1.8,9.4,11.3,15.6,19.1,17.5,10.9,8.9,2.3,-1.8,-5.6,-5.4,-0.6,5.1,13.6,17.3,18.8,15.6,13.8,5.8,2.2,-6.5,-14.5,-8.4,-1.1,8.3,16.7,18.8,26.0,21.8,11.7,3.8,2.7,-7.6,-7.5,-11.0,-2.0,6.4,14.6,19.0, 23.4,18.7,12.1,6.6,0.2,-0.1,-6.8,-11.7,-3.1,8.2,15.1,17.1,20.9,17.7,12.9,6.5,1.6,-8.6,-8.5,-3.5,-6.5,6.1,16.9,19.8,18.9,18.3,10.3,6.6,4.0,-1.7,-8.6,-1.9,2.8,7.0,16.0,16.1,21.1,19.2,12.3,3.7,-1.3,-3.9,-4.4,-2.2,2.0,6.1,14.2,17.9,18.3,17.6,13.8,4.4,0.8,0.2,-10.1,-0.6,0.3,8.1,15.0,18.2,20.9,19.5,11.4,4.4,-2.7,-4.6,7.8,-4.6,2])
train_y = np.array([
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9,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, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])

# Reshape data
train_x = train_x.astype(np.float32).reshape(1, 833, 1)
train_y = train_y.astype(np.float32).reshape(1, 840, 1)

# Build the model
model = Sequential()

model.add(LSTM(units=128, activation='tanh', input_shape=(24, 1), return_sequences=True))
model.add(Dropout(0.2))
model.add(LSTM(units=128, activation='tanh', return_sequences=True))
model.add(Dropout(0.2))
model.add(LSTM(units=128, activation='tanh', return_sequences=True))
model.add(Dropout(0.2))

model.add(Dense(units=1, activation='linear'))

# Compile the model
model.compile(optimizer='adam', loss='mse')

# Train the model
model.fit(train_x, train_y, batch_size=32, epochs=283)
\------------------------\
last_840 = train_x[0][-840:]

last_840 = last_840.reshape(1, 840, 1)

predictions = model.predict(last_840)
for i in range(12):
  print(predictions[0][i])

Изначально это нейросеть угадывающая погоду, проблема в следящем когда запускаю код у меня выдает ошибку (картинка 1) я погуглил и понял что просто стоит
переписать значение reshape(1, 840, 1) но я не очень понял какие значения надо переписать, если ориентироваться по ошибкам то после всех исправлений выдаётся еще одна ошибка на картинке 2 можно совет как это поправить или что то
нужно переписать?
  • Вопрос задан
  • 73 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы
23 нояб. 2024, в 01:31
1000 руб./за проект
23 нояб. 2024, в 00:16
2000 руб./за проект