Множественные проблемы и ошибки с тензорным массивом потока/матрицей/формой тензора и манипулированием даннымиPython

Программы на Python
Anonymous
Множественные проблемы и ошибки с тензорным массивом потока/матрицей/формой тензора и манипулированием данными

Сообщение Anonymous »

Код: Выделить всё

import tensorflow as tf
import numpy as np
from tqdm import tqdm
from datasets import load_dataset
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
from tensorflow.keras import layers, Input
import random
from datetime import datetime, timedelta
from datasets import load_dataset

from datasets import load_dataset
dataset = load_dataset("csv", data_files="bitcoin_daily/data_btc.csv", split="train")

input_shape = (3, 6)

def GetRandomThirtyDays(dataset):

dates = dataset["date"]
random_date = random.choice(dates)

# Find the index of the random date
random_date_index = dates.index(random_date)

# Get the last 30 days starting from the random date
start_index = max(0, random_date_index - 5)  # Ensure the start index is not negative
last_30_days_dates = dates[start_index:random_date_index]

# Check if all dates exist in the dataset
for date in last_30_days_dates:
if date not in dates:
return GetRandomThirtyDays()  # If any date is missing, recursively call the function to get a new random set of 30 days

# Save the indices of the last 30 days
last_30_days_indices = list(range(start_index, random_date_index + 1))

return  last_30_days_indices, random_date_index + 1
def VerifyIndexExists(dataset, index):
try:
dataset["price"][index]
return dataset["price"][index]
except:
return False
def GetSellPrices(dataset, indices, ):
# Get the sell prices for the last 30 days using the indices
DataDictionary = []
Destroyed = False
for index in indices:
# Get the sell price, market_caps and the volumes for the current index IF it exists and return it. If anything is nil (destroyed)

try:
if dataset["price"][index] == None:
Destroyed = True
break
sell_price = dataset["price"][index]
if dataset["market_caps"][index] == None:
Destroyed = True
break
market_cap = dataset["market_caps"][index]
if dataset["total_volumes"][index] == None:
Destroyed = True
break
volume = dataset["total_volumes"][index]
DataDictionary.append([sell_price, market_cap, volume])
except:
Destroyed = True

return DataDictionary, Destroyed

def Get30DayData(dataset):
indices, answerIndex = GetRandomThirtyDays(dataset) #Get 30 random dates
ThirtyDayDataDictionary, Destroyed = GetSellPrices(dataset, indices)
# go back recursively if we are destroyed
PredictionAnswer = VerifyIndexExists(dataset, answerIndex)
if not PredictionAnswer:
return Get30DayData(dataset)
if Destroyed:
return Get30DayData(dataset)
return ThirtyDayDataDictionary, PredictionAnswer

model = tf.keras.Sequential([
layers.Input(shape=input_shape),  # Input layer with specified shape
layers.Flatten(),
layers.Dense(64, activation='relu'),
layers.Dense(10, activation='softmax'),
layers.Dense(1, activation='sigmoid')
])

model.compile(optimizer="adam", loss="mean_squared_error", metrics=["accuracy"])

X_training = []
answer = []
for _ in tqdm(range(20)):
X, y = Get30DayData(dataset)
if X:
X_training.append(X)
answer.append(y)

X_training_np = np.array(X_training)
answer = np.array(X_training)

model.fit(X_training_np, answer, epochs=300, batch_size=1, verbose=0)
model.evaluate(X_training_np, answer, verbose=2)

Это мой код, и я получаю несколько ошибок случайной формы. Я новичок в тензорном потоке. Причина, по которой я использую данные только за последние 5 дней, заключается в том, что их легче читать в виде журнала. Будем благодарны за помощь!
Я пытаюсь обучить ИНС на основе списка 3 на 5, чтобы собирать все данные за последние дни, используя в качестве прогноза число с плавающей запятой.

Подробнее здесь: https://stackoverflow.com/questions/784 ... ape-and-da

Вернуться в «Python»