我正在尝试扩展我的编程技能,并想尝试机器学习。这只是为了学习,并不是为了什么严肃的事情。话虽如此,我从一个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,)
我错过了什么?在Stack Overflow上搜索,似乎需要将y变量转换为字符串格式,但我仍然得到错误:
“number of samples=%d” % (len(y), n_samples)) ValueError: Number of labels=50 does not match number of samples=1
回答:
我已经解决了这个问题。
我需要使用X = X[:, None]
来转换数组