简体   繁体   English

Python RandomForestClassifer-未知标签类型:“连续”错误

[英]Python RandomForestClassifer - Unknown label type: 'continuous' error

I am trying to expand my programming skills and thought I would try machine learning. 我试图扩展自己的编程技能,并认为我会尝试机器学习。 So this is for learning and not for anything serious. 所以这是为了学习,而不是为了任何严肃的事情。 With that said, I am retrieving some information from a sqlite database, then trying to run it through a RandomForestClassifier but I get an error. 话虽如此,我正在从sqlite数据库中检索一些信息,然后尝试通过RandomForestClassifier运行它,但出现错误。

line 172, in check_classification_targets raise ValueError("Unknown label type: %r" % y_type) ValueError: Unknown label type: 'continuous'" 第172行,在check_classification_targets中引发ValueError(“未知标签类型:%r”%y_type)ValueError:未知标签类型:“连续”

my code is as follows: 我的代码如下:

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)

My arrays are of the shape: y.shape (50,) x.shape (50,) 我的数组具有以下形状:y.shape(50,)x.shape(50,)

What am I missing? 我想念什么? Searching SO it seems like it needs the y variable in a string format but I still get the error: 搜索SO似乎需要字符串格式的y变量,但是我仍然收到错误:

"number of samples=%d" % (len(y), n_samples)) ValueError: Number of labels=50 does not match number of samples=1 “样本数=%d”%(len(y),n_samples))ValueError:标签数= 50与样本数不匹配= 1

Figured it out. 弄清楚了。

I needed to transform the array with X = X[:, None] 我需要用X = X[:, None]变换数组

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM