@Jumbo_python

AttributeError: 'dict' object has no attribute, что делать?

Код:
# Keep only the data for the last year for all companies. We shall be taking only latest data into consideration.
nyse_data.drop_duplicates(subset='ticker_symbol', keep='last', inplace=True)
Svm_model = {}
Svm_model.fit()
# Adding in the predicted values for bankruptcy in the original dataset
nyse_data["stability"] = Svm_model.fit(scaler.transform(nyse_data[["total_assets", "total_liabilities"]]))
print ("Companies predicted to go bankrupt over a 4 year period: ", len(nyse_data.loc[nyse_data["stability"] != 1, "ticker_symbol"]))


Ошибка:
Traceback (most recent call last)
AttributeError
<ipython-input-69-aa92dfaf065a> in <module>
      2 nyse_data.drop_duplicates(subset='ticker_symbol', keep='last', inplace=True)
      3 Svm_model = {}
----> 4 Svm_model.fit()
      5 # Adding in the predicted values for bankruptcy in the original dataset
      6 nyse_data["stability"] = Svm_model.fit(scaler.transform(nyse_data[["total_assets", "total_liabilities"]]))
AttributeError: 'dict' object has no attribute 'fit'


Второй Код:
count = 0
stock_predictions = {}
stats.normaltest = {}
for i in weekly_stock_prices_log:
    # Splitting available data into training for accuracy check using remaining data points
    split_point = len(weekly_stock_prices_log[i]) - 20
    # Number of weeks from last date in dataset to 2018-12-31 = 117
    num_of_predictions = len(weekly_stock_prices_log[i]) + 117
    training = weekly_stock_prices_log[i][0:split_point]
    model = {}
    
    # Try modelling first using p=2, q=1, if that fails use p=1, q=0
    try:
        model = arima_model.ARMA(training["close"], order=(2,1)).fit()
    except:
        model = arima_model.ARMA(training["close"], order=(1,0)).fit()
    
    #Add the predicted values in a dataframe for ease of further operations.
    daterange = pd.date_range(training.index[0], periods=num_of_predictions, freq = 'W-MON').tolist()
    stock_predictions[i] = pd.DataFrame(columns=["date", "prediction"])
    stock_predictions[i]["date"] = daterange
    stock_predictions[i]["prediction"] = model.predict(start=0, end=num_of_predictions)
    stock_predictions[i].set_index("date", inplace=True)
    
    # Draw a QQPlot to check if the residuals are evenly distributed
    if count < 5:
        resid = model.resid
        print("For "+i+": ",stats.normaltest(resid))
        qqplot(resid, line='q', fit=True)
        plt.show()
        count += 1

Traceback (most recent call last)
AttributeError
<ipython-input-50-5b2fa11eb049> in <module>
      1 count = 0
      2 stock_predictions = {}
----> 3 stats.normaltest = {}
      4 for i in weekly_stock_prices_log:
      5     # Splitting available data into training for accuracy check using remaining data points
AttributeError: 'dict' object has no attribute 'normaltest'
  • Вопрос задан
  • 2607 просмотров
Пригласить эксперта
Ответы на вопрос 1
LaRN
@LaRN
Senior Developer
Судя по коду у вас опечатка.
Вот тут вы создаёте переменную типа "словарь"
Svm_model = {}
Вот тут вы вызываете метод, которого нет у словаря.
Svm_model.fit()

Скорее всего вам нужно тут вызвать конструктор класса, который вы потом начнёте обучаюсь вызвав метод fit(), например так.
Svm_model = LinearRegression()
Ответ написан
Комментировать
Ваш ответ на вопрос

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

Войти через центр авторизации
Похожие вопросы