python-3.x - TypeError:fit()缺少1个必需的位置参数: 'y'

标签 python-3.x pandas scikit-learn

我正在尝试使用高斯朴素贝叶斯“分类器”预测经济周期。

数据(输入X):

             SPY    Interest Rate    Unemployment   Employment  CPI
Date                    
1997-01-02   56.05     7.82            9.7           3399.9     159.100
1997-02-03   56.58     7.65            9.8           3402.8     159.600
1997-03-03   54.09     7.90            9.9           3414.7     160.000

目标(输出Y):
    Economy
0   Expansion
1   Expansion
2   Expansion
3   Expansion

下面是我的代码:
from sklearn.naive_bayes import GaussianNB
from sklearn import metrics
from sklearn.cross_validation import train_test_split
X = data
Y = target
model = GaussianNB
X_train, X_test, Y_train, Y_test = train_test_split(X,Y)
model.fit(X_train, Y_train)

以下是错误:
TypeError                                 Traceback (most recent call last)
<ipython-input-132-b0975752a19f> in <module>()
  6 model = GaussianNB
  7 X_train, X_test, Y_train, Y_test = train_test_split(X,Y)
  ----> 8 model.fit(X_train, Y_train)

  TypeError: fit() missing 1 required positional argument: 'y'

我究竟做错了什么?我该如何解决此问题/错误?

最佳答案

您忘记了括号“()”:

model = GaussianNB()

关于python-3.x - TypeError:fit()缺少1个必需的位置参数: 'y',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35996970/

相关文章:

python - 从 python 有序字典中删除一个键的复杂性

pandas - 数据 ['column_name' ] 与 data.column_name 之间是否存在显着差异

python - 具有分类和连续属性的多类多输出分类,无需在 python 中进行编码

python - 值错误: Classification metrics can't handle a mix of unknown and binary targets?

python - 我无法为 python 3.7 安装 Scikit-learn

python - 如何在 docker 容器中使用 'keyboard' python 模块而不出现错误?

python - 如何仅对数据集的特定列进行标签编码?

python - 按日期排序和排名,在 pandas df 中的一组

python - Pandas 在交叉值中找到重复项

python - 在 Tkinter 中将图像添加到按钮