类型错误:“模块”对象在 MLP 回归器中不可调用

尝试运行此命令时,我收到以下错误。我真的不知道如何解决这个问题。由于我对此很陌生,所以我非常感谢任何帮助。


在这里,我使用不同的模型来检查哪一个在这里最好。


检查此导入代码:


import numpy as np 

import matplotlib.pyplot as plt 

import matplotlib.colors as mcolors

import pandas as pd 

import plotly.express as px

from datetime import date, timedelta

import random

import math

import time

import operator 

import folium

import plotly.offline as py


from sklearn.linear_model import LinearRegression, BayesianRidge

from sklearn.model_selection import RandomizedSearchCV, train_test_split

from sklearn.preprocessing import PolynomialFeatures

from fbprophet import Prophet

from fbprophet.plot import plot_plotly, add_changepoints_to_plot

from sklearn import preprocessing, cross_validation

from sklearn.tree import DecisionTreeRegressor

from sklearn.neural_network import MLPRegressor

from sklearn.svm import SVR

from sklearn.metrics import mean_squared_error, mean_absolute_error

from statsmodels.tsa.arima_model import ARIMA

from statsmodels.graphics.tsaplots import plot_acf, plot_pacf

import statsmodels.api as sm

from keras.models import Sequential

from keras.layers import LSTM,Dense

from keras.layers import Dropout

from sklearn.preprocessing import MinMaxScaler

from tensorflow.keras.preprocessing.sequence import TimeseriesGenerator


plt.style.use('fivethirtyeight')

%matplotlib inline 

多项式回归的模型开发


data1 = confirmed_df.melt(value_vars=dates1, var_name='Date', value_name='Confirmed')

data1 = data1.groupby('Date')['Confirmed'].sum().reset_index()

data1.head()


X = pd.DataFrame(data=data1, columns=data1.Date)

y = data1.Confirmed

y -= y.mean()


#cross_validation.train_test_split(x, y, test_size=0.1,random_state=0)

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.1,

                                                    random_state=0)

SMILET
浏览 181回答 2
2回答

茅侃侃

我想你想跟踪你的脚本的性能,但是你需要指定要从中调用方法time()的模块,所以要解决这个问题,只需调用,请参阅下面证明的示例tic=time()tic = time.time()#!/usr/bin/pythonimport time;  # This is required to include time module.ticks = time.time()print "Number of ticks since 12:00am, January 1, 1970:", ticks

慕尼黑8549860

错误告诉您这是一个模块,而不是一个函数。你在剧本的顶部有这样的台词吗?timeimport time如果是这样,那么要获取要在模块中调用函数的当前时间:timetimetic = time.time()如果使用,则可以在运行代码之前捕获此类错误。在调用模块的代码上运行,就好像它是一个函数一样,会产生 .使用宏可以显示差异:mypymypytimeerror: Module not callablereveal_typeimport timereveal_type(time)       # note: Revealed type is '_importlib_modulespec.ModuleType'reveal_type(time.time)  # note: Revealed type is 'def () -> builtins.float'如果您只想从模块中获取函数,则可以专门导入该函数,以便在代码范围内引用该函数而不是整个模块:timetimetimefrom time import timereveal_type(time)       # note: Revealed type is 'def () -> builtins.float'reveal_type(time.time)  # error: "Callable[[], float]" has no attribute "time"因此,现在我们已经将函数直接导入到我们的作用域中,是正确的(因为 是一个函数),而不是(因为该函数没有名为 的成员)。timetime()timetime.time()timetime
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python