随机森林做缺失值填充和特征选择时报编码错误,把模型的n_jobs参数删除就能跑,但跑的太慢了,大佬们什么好的解决方法不
特征选择
for i in estimators:
# 随机森林
feature_RFC = RandomForestClassifier(n_estimators=i, criterion='gini', n_jobs=-1)
# 记录分数
record = []
# 获得每个特征的重要性
importance = feature_RFC.fit(feature_train, train_y).feature_importances_
# 用numpy.linspace创建等差序列
threshold = np.linspace(0, importance.max(), 10)
for a in threshold:
x_embedded = SelectFromModel(feature_RFC, threshold=a).fit_transform(feature_train, train_y)
score = cross_val_score(feature_RFC, x_embedded, train_y, scoring='roc_auc', cv=5, error_score=np.nan).mean()
record.append(score)
# plotly绘图
fig.add_trace(go.Scatter(x=threshold, y=record, mode='lines', name=i))
fig.show()
报错
File "E:\Anaconda3\lib\site-packages\joblib\_memmapping_reducer.py", line 590, in register_folder_finalizer
resource_tracker.register(pool_subfolder, "folder")
File "E:\Anaconda3\lib\site-packages\joblib\externals\loky\backend\resource_tracker.py", line 191, in register
self._send('REGISTER', name, rtype)
File "E:\Anaconda3\lib\site-packages\joblib\externals\loky\backend\resource_tracker.py", line 204, in _send
msg = '{0}:{1}:{2}\n'.format(cmd, name, rtype).encode('ascii')
UnicodeEncodeError: 'ascii' codec can't encode characters in position 18-21: ordinal not in range(128)