mlxtend.feature_selection 前向选择不适用于 SVM 线性内核?
mlxtend.feature_selection forward selection not working with SVM linear kernel?
所以我正在使用 SVM 和 mlxtend packege 执行特征选择。 X 是具有特征的数据框,y 是目标变量。这是我的代码的一部分。
from sklearn.svm import SVC
from mlxtend.feature_selection import SequentialFeatureSelector as SFS
def SFFS(X, y, C_GS, gamma_GS, kernel_GS):
sfs = SFS(SVC(kernel = kernel_GS, C = C_GS, gamma = gamma_GS),
k_features = (1, num_of_features),
forward= True,
floating = False,
verbose= 2,
scoring= 'roc_auc',
#scoring= 'accuracy',
cv = 10,
n_jobs= -1
).fit(X, y)
return sfs
def SFFS_lin(X, y, C_GS, kernel_GS):
sfs = SFS(SVC(kernel = kernel_GS, C = C_GS),
k_features = (1, num_of_features),
forward= True,
floating = False,
verbose= 2,
scoring= 'roc_auc',
cv = 10,
n_jobs= -1
).fit(X, y)
return sfs
def featureNames(sfs):
Feature_Names = sfs.k_feature_names_
return Feature_Names
sfs_lin = SFFS_lin(X, y, 1,'linear')
#sfs_rbf = SFFS(X, y, 1, 'auto', 'rbf')
names = featureNames(sfs_lin)
print(names)
代码开始 运行,但很快就卡住了:
[Parallel(n_jobs=-1)]: Using backend LokyBackend with 8 concurrent
workers. [Parallel(n_jobs=-1)]: Done 28 out of 28 | elapsed: 2.5s
remaining: 0.0s [Parallel(n_jobs=-1)]: Done 28 out of 28 |
elapsed: 2.5s finished
[2021-01-24 00:01:57] Features: 1/28 -- score:
0.6146428161908037[Parallel(n_jobs=-1)]: Using backend LokyBackend with 8 concurrent workers.
使用rbf内核时,代码运行的很漂亮。如果我通过将 forward 参数设置为 False 来更改函数以执行向后消除,它运行得很好
forward=False,
它运行得很漂亮。在使用线性核进行前向选择时似乎会出现冻结问题。
这是一个愚蠢的错误还是我遗漏了一些微不足道的东西?
系统信息:
Python 3.8.5
scikit-learn 0.24.1
mlxtend 0.18.0
看来这只是一个愚蠢的错误。
切换交叉验证
cv = 10
参数为 9 并运行..
所以我正在使用 SVM 和 mlxtend packege 执行特征选择。 X 是具有特征的数据框,y 是目标变量。这是我的代码的一部分。
from sklearn.svm import SVC
from mlxtend.feature_selection import SequentialFeatureSelector as SFS
def SFFS(X, y, C_GS, gamma_GS, kernel_GS):
sfs = SFS(SVC(kernel = kernel_GS, C = C_GS, gamma = gamma_GS),
k_features = (1, num_of_features),
forward= True,
floating = False,
verbose= 2,
scoring= 'roc_auc',
#scoring= 'accuracy',
cv = 10,
n_jobs= -1
).fit(X, y)
return sfs
def SFFS_lin(X, y, C_GS, kernel_GS):
sfs = SFS(SVC(kernel = kernel_GS, C = C_GS),
k_features = (1, num_of_features),
forward= True,
floating = False,
verbose= 2,
scoring= 'roc_auc',
cv = 10,
n_jobs= -1
).fit(X, y)
return sfs
def featureNames(sfs):
Feature_Names = sfs.k_feature_names_
return Feature_Names
sfs_lin = SFFS_lin(X, y, 1,'linear')
#sfs_rbf = SFFS(X, y, 1, 'auto', 'rbf')
names = featureNames(sfs_lin)
print(names)
代码开始 运行,但很快就卡住了:
[Parallel(n_jobs=-1)]: Using backend LokyBackend with 8 concurrent workers. [Parallel(n_jobs=-1)]: Done 28 out of 28 | elapsed: 2.5s remaining: 0.0s [Parallel(n_jobs=-1)]: Done 28 out of 28 | elapsed: 2.5s finished
[2021-01-24 00:01:57] Features: 1/28 -- score: 0.6146428161908037[Parallel(n_jobs=-1)]: Using backend LokyBackend with 8 concurrent workers.
使用rbf内核时,代码运行的很漂亮。如果我通过将 forward 参数设置为 False 来更改函数以执行向后消除,它运行得很好
forward=False,
它运行得很漂亮。在使用线性核进行前向选择时似乎会出现冻结问题。 这是一个愚蠢的错误还是我遗漏了一些微不足道的东西?
系统信息:
Python 3.8.5
scikit-learn 0.24.1
mlxtend 0.18.0
看来这只是一个愚蠢的错误。
切换交叉验证
cv = 10
参数为 9 并运行..