Python RandomForestClassifer - 未知标签类型:'continuous' 错误

Python RandomForestClassifer - Unknown label type: 'continuous' error

我正在尝试扩展我的编程技能,并认为我会尝试机器学习。所以这是为了学习而不是为了任何严肃的事情。话虽如此,我正在从 sqlite 数据库中检索一些信息,然后尝试通过 RandomForestClassifier 运行 它,但出现错误。

line 172, in check_classification_targets raise ValueError("Unknown label type: %r" % y_type) ValueError: Unknown label type: 'continuous'"

我的代码如下:

series= cur.fetchall()
y = [x[1] for x in series]
x = [x[2] for x in series]
y = array(y).astype(float)
x = array(x).astype(int)
rf_model = RandomForestClassifier()
rf_model.fit(x, y)

我的数组是这样的: y.shape (50,) x.shape (50,)

我错过了什么?搜索所以它似乎需要字符串格式的 y 变量,但我仍然收到错误:

"number of samples=%d" % (len(y), n_samples)) ValueError: Number of labels=50 does not match number of samples=1

想通了。

我需要用 X = X[:, None]

转换数组