我正在尝试将朴素高斯拟合到数据集中。代码如下:
import pandas as pd
import numpy as np
from sklearn.naive_bayes import GaussianNB
df = pd.read_csv('train_data.csv')
X = df.iloc[:,0:23]
X
Y = df.iloc[:,24:25]
clf = GaussianNB()
clf.fit(X, Y)
这就是数据的样子
^{pr2}$默认的“下一个月”是目标变量。这是一个二元分类问题。Y包含最后一列。但它给出了一个错误:
ValueError Traceback (most recent call last)
<ipython-input-24-d9885fbe19e4> in <module>()
3
4 clf = GaussianNB()
----> 5 clf.fit(X, Y)
6
7
/home/fatima/anaconda2/lib/python2.7/site-packages/sklearn/naive_bayes.pyc in fit(self, X, y, sample_weight)
180 Returns self.
181 """
--> 182 X, y = check_X_y(X, y)
183 return self._partial_fit(X, y, np.unique(y), _refit=True,
184 sample_weight=sample_weight)
/home/fatima/anaconda2/lib/python2.7/site-packages/sklearn/utils/validation.pyc in check_X_y(X, y, accept_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, multi_output, ensure_min_samples, ensure_min_features, y_numeric, warn_on_dtype, estimator)
524 dtype=None)
525 else:
--> 526 y = column_or_1d(y, warn=True)
527 _assert_all_finite(y)
528 if y_numeric and y.dtype.kind == 'O':
/home/fatima/anaconda2/lib/python2.7/site-packages/sklearn/utils/validation.pyc in column_or_1d(y, warn)
560 return np.ravel(y)
561
--> 562 raise ValueError("bad input shape {0}".format(shape))
563
564
ValueError: bad input shape (25000, 0)
我要做的就是把声明改成
而且成功了
相关问题 更多 >
编程相关推荐