标签: feature-selection

对于高度相关的特征我们应该做什么?

在我的数据集中,2 个特征C1C2是高度相关的。我做了以下步骤。您能告诉我它是否正确且有意义吗?你有更好的方法吗?

首先我使用线性模型来找到拟合线:C1=a*C2+b

from sklearn import linear_model

reg=linear_model.LinearRegression()
y_reg = data1['C1']
x_reg = data1['C2']
reg.fit(x_reg2,y_reg2)
a=reg.coef_
b=reg.intercept_

print(a,b)
Run Code Online (Sandbox Code Playgroud)

找到 a 和 b 后,我从数据集中删除了 和 并添加了一个新的 Vriable C1C2new=a*C1+b

我的下一个问题是我如何理解这条线是否好?

linear-regression correlation feature-selection

5
推荐指数
1
解决办法
1万
查看次数

SVR 的功能重要性

我想用 SVR 绘制特征重要性,但我不知道是否可以使用支持向量回归这是我的代码。

from sklearn.svm import SVR
C=1e3
svr_lin = SVR(kernel="linear", C=C)
y_lin = svr_lin.fit(X,Y).predict(X)
scores = cross_val_score(svr_lin, X, Y, cv = 5)
print(scores)
print(scores.mean())
print(scores.std())
Run Code Online (Sandbox Code Playgroud)

python feature-selection

5
推荐指数
1
解决办法
3656
查看次数

xgboost.plot_importance() 和 model.feature_importances_ XGBclassifier 之间有什么区别

XGBclassifier 中 xgboost.plot_importance() 和 model.feature_importances_ 有什么区别。

所以我在这里做了一些虚拟数据

import numpy as np
import pandas as pd
# generate some random data for demonstration purpose, use your original dataset here
X = np.random.rand(1000,100)     # 1000 x 100 data
y = np.random.rand(1000).round() # 0, 1 labels
a = pd.DataFrame(X)
a.columns = ['param'+str(i+1) for i in range(len(a.columns))]
b = pd.DataFrame(y)

import xgboost as xgb
from xgboost import XGBClassifier
from xgboost import plot_importance
from matplotlib import pyplot as plt
from sklearn.model_selection import train_test_split

model = …
Run Code Online (Sandbox Code Playgroud)

python feature-selection dimensionality-reduction xgboost xgbclassifier

5
推荐指数
1
解决办法
2021
查看次数

如何使用R Random forest减少没有离散类的属性?

我想使用随机森林来减少属性.我的数据中存在的一个问题是我没有离散类 - 仅连续,这表示示例与"正常"的不同之处.此类属性是从零到无穷大的一种距离.有没有办法使用随机森林这样的数据?

statistics r machine-learning feature-selection random-forest

4
推荐指数
1
解决办法
1883
查看次数

如何从R中的GLM调用中检索原始变量名称列表?

当使用glm中的R功能的一个可以使用的功能,如addNAlog内部formula参数.比方说,我们有一个数据帧Data有4列:Class,var1这是因素和var2,var3这是数值变量,我们适合:

Model <- glm(data  = Data, 
         formula   = Class ~ addNA(var1) + var2+ log(var3),  
         family    = binomial)
Run Code Online (Sandbox Code Playgroud)

在glm输出变量1现在将被调用addNA(var1)(例如,在Model$xlevels),而变量3将被调用log(var3).

是否可以从glm输出中检索一个列表,该列表指示var1,var2和var3是从数据帧中提取的,而变量名中没有出现addNA(var1)或log(var3)?

更一般的是,调用glm 之后, glm函数内生成任何变换/交叉项等之前,是否有可能推断出哪些列是通过glm从输入数据帧中提取的?

r model-fitting feature-selection glm

4
推荐指数
1
解决办法
1480
查看次数

Vowpal Wabbit交互冗余

我很好奇大众通过-q参数创建交互术语的方式.

为了说明的目的,我使用这个玩具数据,称为cats.vm:

1 |a black |b small  green |c numvar1:1.62 numvar2:342 |d cat |e numvar3:554
1 |a white |b large yellow |c numvar1:1.212 numvar2:562 |d cat |e numvar3:632
-1 |a black |b small green |c numvar1:12.03 numvar2:321 |d hamster |e numvar3:754
1 |a white |b large green |c numvar1:5.8 numvar2:782 |d dog |e numvar3:234
-1 |a black |b small yellow |c numvar1:2.322 numvar2:488 |d dog |e numvar3:265
1 |a black |b large yellow |c numvar1:3.99 numvar2:882 |d hamster |e numvar3:543 …
Run Code Online (Sandbox Code Playgroud)

redundancy quadratic feature-selection vowpalwabbit

4
推荐指数
1
解决办法
940
查看次数

在Vowpal Wabbit中,命名空间和功能有什么区别?

在R或python中进行分析时,我们只知道特征名称(它们的值)并使用它们.在Vowpal Wabbit,我们也有命名空间.

我无法理解:a.Namespace是什么意思; 湾 它与功能有何不同; C.什么时候使用?什么时候不用?也就是说,我们可以避免使用它.d.它是如何使用的?

将会感激一两个例子.很抱歉这么多问题.

namespaces command-line-arguments feature-selection vowpalwabbit

4
推荐指数
1
解决办法
1407
查看次数

如何为GradientBoostingClassifier计算要素重要性

我正在使用scikit-learn的渐变增强树分类器GradientBoostingClassifier.它使功能重要性分数可用feature_importances_.如何计算这些要素的重要性?

我想了解scikit-learn正在使用什么算法,以帮助我理解如何解释这些数字.该算法未在文档中列出.

python machine-learning feature-selection scikit-learn

4
推荐指数
1
解决办法
4841
查看次数

当培训和测试中的功能数量不同时,如何在生产环境中处理“一键编码”?

在进行某些实验时,我们通常训练70%,然后测试33%。但是,当您的模型投入生产时会发生什么?可能会发生以下情况:

训练集:

-----------------------
| Ser |Type Of Car    |
-----------------------
|  1  | Hatchback     |
|  2  | Sedan         |
|  3  | Coupe         |
|  4  | SUV           |
-----------------------
Run Code Online (Sandbox Code Playgroud)

经过一键热编码后,我们得到的是:

-----------------------------------------
| Ser | Hatchback | Sedan | Coupe | SUV |
-----------------------------------------
|  1  |     1     |   0   |   0    |  0 |
|  2  |     0     |   1   |   0    |  0 |
|  3  |     0     |   0   |   1    |  0 |
|  4 …
Run Code Online (Sandbox Code Playgroud)

python machine-learning feature-selection one-hot-encoding

4
推荐指数
2
解决办法
701
查看次数

何时使用交叉验证和网格搜索在imblearn管道中进行特征选择

目前,我正在建立数据严重不平衡的分类器。我正在使用imblearn管道首先到达StandardScaling,SMOTE,然后使用gridSearchCV进行分类。这确保了在交叉验证期间完成了升采样。现在,我想将feature_selection包含到我的管道中。我应该如何将这一步骤纳入管道中?

model = Pipeline([
        ('sampling', SMOTE()),
        ('classification', RandomForestClassifier())
    ])

param_grid = { 
    'classification__n_estimators': [10, 20, 50],
    'classification__max_depth' : [2,3,5]
}

gridsearch_model = GridSearchCV(model, param_grid, cv = 4, scoring = make_scorer(recall_score))
gridsearch_model.fit(X_train, y_train)
predictions = gridsearch_model.predict(X_test)
print(classification_report(y_test, predictions))
print(confusion_matrix(y_test, predictions))
Run Code Online (Sandbox Code Playgroud)

python sampling feature-selection imblearn

4
推荐指数
1
解决办法
688
查看次数