2017-07-06 19 views
1

我正在尝试做一些机器学习。我试图预测一篇文章的参与时间。我有我的X数据集如下:SciKit-Learn:使用随机森林时的JoblibException

_text_word_length _title_char_length _title_word_length _text_char_length 
0 1306    53     7     8056  
1 1075    62     11     6127 

和我的目标Y值只是彩车代表连接时间。

我用SciKit-了解如下:

from sklearn.ensemble import RandomForestRegressor 
from sklearn.model_selection import cross_val_score, KFold 
import numpy as np 
clf = RandomForestRegressor(n_jobs=-1, n_estimators=250, max_features = 0.8, verbose = 2) 
score = cross_val_score(estimator = clf, X = X1, y = Y1, cv = KFold(n_splits = 5, random_state = 100), n_jobs = -1, \ 
         scoring = "neg_mean_squared_error") 
np.mean([np.sqrt(-x) for x in score]) 

因为我用详细模式,它输出的随机森林的树木。它获得通过几乎所有的树木,然后我得到这个:

JoblibException: JoblibException 
___________________________________________________________________________ 
Multiprocessing exception: 

然后有一吨的文本(不会在这里重现,但可根据要求)。在最后,我看到:

ValueError: I/O operation on closed file 

我完全失去了,因为非常相似的代码昨天的工作,所以我不知道我在做什么错误。

任何想法?

谢谢!

回答

2

你可以尝试下面的东西吗?因此,如果名称 =='main'具有相应的缩进,请将所有代码放在后面。

from sklearn.ensemble import RandomForestRegressor 
from sklearn.model_selection import cross_val_score, KFold 
import numpy as np 

if __name__ =='main': 

    clf = RandomForestRegressor(n_estimators=250, max_features = 0.8, verbose = 2) 
    score = cross_val_score(estimator = clf, X = X1, y = Y1, cv = KFold(n_splits = 5, random_state = 100), n_jobs = -1,scoring = "neg_mean_squared_error") 
    np.mean([np.sqrt(-x) for x in score]) 

注意 1)在cross_val_score之前得分= ..应该有一个昏迷而不是一个切片(/)

2)仅使用一次n_jobs = -1内cross_val_score