首页 > 解决方案 > 我该如何解决这个问题,VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences

问题描述

:2: VisibleDeprecationWarning: 从不规则的嵌套序列(这是一个列表或元组的列表或元组或具有不同长度或形状的 ndarray 的列表或元组)创建一个 ndarray 已被弃用。如果您打算这样做,则必须在创建 ndarray x_train, y_train = np.array(x_train), np.array(y_train) 时指定 'dtype=object'

这是什么意思,我该如何解决?这是我正在运行的代码:

    #import libraries:
    import math
    import time
    import pandas as pd
    import datetime
    import numpy as np
    import streamlit as st
    import matplotlib.pyplot as plt
    import pandas_datareader as web
    from tensorflow.keras.models import Sequential
    from sklearn.preprocessing import MinMaxScaler
    from tensorflow.keras.layers import Dense, Dropout, LSTM
    plt.style.use('fivethirtyeight')
    import tensorflow.compat.v2 as tf
    
    #Scale the data:
    scaler = MinMaxScaler(feature_range=(0,1))
    scaled_data = scaler.fit_transform(dataset)
    scaled_data

    #Create the training dataset:
    #Create the scaled training dataset:
    train_data = scaled_data[0:training_data_len, :]
    #Split the data into x_train and y_train datasets:
    x_train = []
    y_train = []

    for i in range(60, len(train_data)):
        x_train.append(train_data[i-60:, 0])
        y_train.append(train_data[1,0])
        if i <= 61:
             print(x_train)
             print(y_train)
             print()

    #Convert the x_train and y_train to numpy arrays:
    x_train, y_train = np.array(x_train), np.array(y_train)

标签: arraysnumpy

解决方案


推荐阅读