我有一个数据集,我想在这些数据上训练我的模型.在训练之后,我需要知道SVM分类器分类中主要贡献者的特征.
对森林算法有一些称为特征重要性的东西,有什么类似的吗?
我正在处理高度不平衡的数据集,我的想法是从我的libSVM模型中获取特征权重值.至于现在,我可以使用线性内核,在那里我可以获得特征权重,但是当我使用rbf或者poly,我无法实现我的目标.
在这里,我使用的sklearn是我的模型,很容易获得线性内核使用的特征权重.coef_.任何人都可以帮我做同样的事情rbf或poly?我到目前为止尝试做的事情如下:
svr = SVC(C=10, cache_size=200, class_weight='auto', coef0=0.0, degree=3.0, gamma=0.12,kernel='rbf', max_iter=-1, probability=True, random_state=0,shrinking=True, tol=0.001, verbose=False)
clf = svr.fit(data_train,target_train)
print clf.coef_
Run Code Online (Sandbox Code Playgroud) 当我在我的程序中运行mean_acc()方法时,有%(min_groups,self.n_splits)),警告)错误...
def mean_acc():
models = [
RandomForestClassifier(n_estimators=200, max_depth=3, random_state=0),
LinearSVC(),
MultinomialNB(),
LogisticRegression(random_state=0)]
CV = 6
cv_df = pd.DataFrame(index=range(CV * len(models)))
entries = []
for model in models:
model_name = model.__class__.__name__
accuracies = cross_val_score(model, features, labels, scoring='accuracy', cv=CV)
for fold_idx, accuracy in enumerate(accuracies):
entries.append((model_name, fold_idx, accuracy))
cv_df = pd.DataFrame(entries, columns=['model_name', 'fold_idx', 'accuracy'])
print(cv_df.groupby('model_name').accuracy.mean())
Run Code Online (Sandbox Code Playgroud)
这些是我使用mean_acc()方法运行程序时显示的错误.我可以知道如何在下面解决这些错误吗?请帮助我看看上面导致这些错误的代码,谢谢!
% (min_groups, self.n_splits)), Warning)
C:\Users\L31307\PycharmProjects\FYP\venv\lib\site-packages\sklearn\model_selection\_split.py:626: Warning: The least populated class in y has only 1 members, which is too few. The minimum number of members in any …Run Code Online (Sandbox Code Playgroud)