0

我在我的一小部分数据上运行 python 中的 mlxtend 详尽功能选择器,并且在 mlxtend.efs.fit 函数内部的变量执行后,我不断收到 unboundlocal 错误。知道为什么吗?我尝试用数据框替换 Xnp,运行 efs.fit 而不使用功能名称,并将切片 [0:10] 替换为数组。

'UnboundLocalError:分配前引用的局部变量'best_subset''截图

使用 python 3.6 在笔记本中运行 mlxtend

Xnp 是一个 float64 形状 (262, 23076) 数组([[44.34, 0.56, 2.66, ..., 27.9 , 6.74, 7.8 ], [42.77, 0.71, 2.78, ..., 0. , 0. , 0. ], [33.91, 0.57, 1.98, ..., 19.74, 4.02, 4.96], ...,

Y 是一个 float64 形状 (262,) 数组([321898.1367 , 236235.3817 , 97439.51583, 112764.3875 , 139780.3192 , 224775.2867 , 133735.2917 , 161081.9575 , ....

feature_names_num 是一个 int32 数组 (23076,) array([ 0, 1,
2, ..., 23074, 23075, 23076])

from numba import jit, njit, vectorize, types

####exchaustive feature selector
import matplotlib.pyplot as pit
from sklearn.neighbors import KNeighborsClassifier as knn
from sklearn.linear_model import LogisticRegression as LGR
from mlxtend.feature_selection import ExhaustiveFeatureSelector
from mlxtend.plotting import plot_sequential_feature_selection


efs = ExhaustiveFeatureSelector(
        #knn(n_neighbors =3),
        #rfc(n_jobs=8),
        LGR(max_iter=100),
        min_features=1,
        max_features=6,
        #scoring = 'neg_mean_squared_error',
        scoring = 'accuracy',
        n_jobs=8,
        print_progress=True,
        cv=7)

efs = efs.fit(Xnp[:,0:10],Y,feature_names_num[0:10])
4

0 回答 0