我使用Weka成功构建了一个分类器.我现在想评估一下我的功能是多么有效或重要.我使用AttributeSelection.但我不知道如何输出具有相应重要性的不同特征.我想简单地按照信息增益分数的降序列出功能!
nlp machine-learning weka feature-selection text-classification
我正在我的开发盒上安装visual studio 2013专业版,并对需要安装哪些功能有疑问..
我将开发一个与SQL Server 2005通信的MVC或Web窗体Web应用程序
我只想安装开发所需的功能,如果我的理解是正确的,请告诉我
混合Visual Studio ---不需要,因为我不打算使用HTML5或XAML或WPF或Silverlight
LightSwitch - 不需要,因为我只开发Web应用程序,与Desktop/Cloud无关
用于C++的Microsoft基础类 - 我将使用C#4.0,我需要这个吗?
Microsoft Office开发人员工具 - 不是必需的,我不会开发与sharepoint或MS Office相关的任何内容,但我需要创建CSV文本文件,读取CSV文件 - 我不需要这个吗?
不需要Microsoft SQL Server数据工具 - 它安装SQL Server 2012组件,但我的应用程序与SQL Server 2005对话 - 我可能使用实体框架,我需要这个吗?
Microsoft Web开发人员工具 - 必需
银灯开发套件 - 不需要应用程序没有任何Silver灯开发/功能 -
我使用管道和grid_search来选择最佳参数,然后使用这些参数来拟合最佳管道('best_pipe').但是,由于feature_selection(SelectKBest)在管道中,所以没有适用于SelectKBest.
我需要知道'k'所选功能的功能名称.有任何想法如何检索它们?先感谢您
from sklearn import (cross_validation, feature_selection, pipeline,
preprocessing, linear_model, grid_search)
folds = 5
split = cross_validation.StratifiedKFold(target, n_folds=folds, shuffle = False, random_state = 0)
scores = []
for k, (train, test) in enumerate(split):
X_train, X_test, y_train, y_test = X.ix[train], X.ix[test], y.ix[train], y.ix[test]
top_feat = feature_selection.SelectKBest()
pipe = pipeline.Pipeline([('scaler', preprocessing.StandardScaler()),
('feat', top_feat),
('clf', linear_model.LogisticRegression())])
K = [40, 60, 80, 100]
C = [1.0, 0.1, 0.01, 0.001, 0.0001, 0.00001]
penalty = ['l1', 'l2']
param_grid = [{'feat__k': K,
'clf__C': C,
'clf__penalty': penalty}]
scoring …Run Code Online (Sandbox Code Playgroud) 我正在使用带有python的spark 2.2.我正在使用ml.feature模块中的PCA.我正在使用VectorAssembler将我的功能提供给PCA.为了澄清,假设我有一个包含三列col1,col2和col3的表,那么我正在做:
from pyspark.ml.feature import VectorAssembler
assembler = VectorAssembler(inputCols=table.columns, outputCol="features")
df = assembler.transform(table).select("features")
from pyspark.ml.feature import PCA
pca = PCA(k=2, inputCol="features", outputCol="pcaFeatures")
model = pca.fit(df)
Run Code Online (Sandbox Code Playgroud)
这时我运行了2个组件的PCA,我可以看看它的值:
m = model.pc.values.reshape(3, 2)
Run Code Online (Sandbox Code Playgroud)
它对应于3(=我原始表中的列数)行和2(=我的PCA中的组件数)列.我的问题是这里的三行是否与我在上面的向量汇编程序中指定输入列的顺序相同?为进一步澄清,上述矩阵对应于:
| PC1 | PC2 |
---------|-----|-----|
col1 | | |
---------|-----|-----|
col2 | | |
---------|-----|-----|
col3 | | |
---------+-----+-----+
Run Code Online (Sandbox Code Playgroud)
请注意,此处的示例仅为了清楚起见.在我真正的问题中,我正在处理~1600列和一堆选择.我在spark文档中找不到任何明确的答案.我想这样做从原始表中选择最佳列/功能,以根据主要组件训练我的模型.还是有别的/更好的火花ML PCA,我应该看着推断这样的结果?
或者我不能使用PCA,并且必须使用其他技术,如spearman排名等?
在下面的示例中,我使用Twitter数据集执行情感分析。我使用sklearn管道执行一系列转换,添加功能并添加分类器。最后一步是可视化具有较高预测能力的单词。当我不使用功能选择时,它工作正常。但是,当我使用它时,得到的结果毫无意义。我怀疑在应用特征选择时,文本特征的顺序会发生变化。有办法解决这个问题吗?
以下代码已更新,以包含正确的答案
from sklearn.base import BaseEstimator, TransformerMixin
from sklearn.pipeline import Pipeline, FeatureUnion
features= [c for c in df.columns.values if c not in ['target']]
target = 'target'
#train test split
X_train, X_test, y_train, y_test = train_test_split(df[features], df[target], test_size=0.2,stratify = df5[target], random_state=0)
#Create classes which allow to select specific columns from the dataframe
class NumberSelector(BaseEstimator, TransformerMixin):
def __init__(self, key):
self.key = key
def fit(self, X, y=None):
return self
def transform(self, X):
return X[[self.key]]
class TextSelector(BaseEstimator, TransformerMixin):
def __init__(self, key):
self.key = key …Run Code Online (Sandbox Code Playgroud) df.idxmax() 返回沿轴(行或列)的最大值,但我希望 arg_max(df) 在整个数据帧上,它返回一个元组(行,列)。
我想到的用例是特征选择,其中我有一个相关矩阵,并且想要“递归”删除具有最高相关性的特征。我对相关矩阵进行预处理以考虑其绝对值并将对角线元素设置为 -1。然后我建议使用rec_drop,它递归地删除具有最高相关性的特征对中的一个(受到截止值:max_allowed_correlation),并返回最终的特征列表。例如:
S = S.abs()
np.fill_diagonal(S.values,-1) # so that max can't be on the diagonal now
S = rec_drop(S,max_allowed_correlation=0.95)
def rec_drop(S, max_allowed_correlation=0.99):
max_corr = S.max().max()
if max_corr<max_allowed_correlation: # base case for recursion
return S.columns.tolist()
row,col = arg_max(S) # row and col are distinct features - max can't be on the diagonal
S = S.drop(row).drop(row,axis=1) # removing one of the features from S
return rec_drop(S, max_allowed_correlation)
Run Code Online (Sandbox Code Playgroud) 我有一个带有邮政编码列的数据集。它们在输出中具有一定的意义,我想将其用作一项功能。我正在使用随机森林模型。
我需要有关使用邮政编码列作为功能的最佳方法的建议。(例如,我应该获取该邮政编码的纬度/经度,而不是直接输入邮政编码等)
提前致谢 !!
zipcode machine-learning feature-selection random-forest h2o
我一直在尝试使用 LASSO 进行无监督特征选择(通过删除类列)。数据集包括分类(因子)和连续(数字)变量。链接在这里。我构建了一个设计矩阵,使用model.matrix()它为每个级别的分类变量创建虚拟变量。
dataset <- read.xlsx("./hepatitis.data.xlsx", sheet = "hepatitis", na.strings = "")
names_df <- names(dataset)
formula_LASSO <- as.formula(paste("~ 0 +", paste(names_df, collapse = " + ")))
LASSO_df <- model.matrix(object = formula_LASSO, data = dataset, contrasts.arg = lapply(dataset[ ,sapply(dataset, is.factor)], contrasts, contrasts = FALSE ))
### Group LASSO using gglasso package
gglasso_group <- c(1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, …Run Code Online (Sandbox Code Playgroud) Sklearn 在#15075中有一个实现此功能的提案,但与此同时,eli5建议将其作为解决方案。但是,我不确定我是否以正确的方式使用它。这是我的代码:
from sklearn.datasets import make_friedman1
from sklearn.feature_selection import RFECV
from sklearn.svm import SVR
import eli5
X, y = make_friedman1(n_samples=50, n_features=10, random_state=0)
estimator = SVR(kernel="linear")
perm = eli5.sklearn.PermutationImportance(estimator, scoring='r2', n_iter=10, random_state=42, cv=3)
selector = RFECV(perm, step=1, min_features_to_select=1, scoring='r2', cv=3)
selector = selector.fit(X, y)
selector.ranking_
Run Code Online (Sandbox Code Playgroud)
有几个问题:
我不确定我是否以正确的方式使用交叉验证。PermutationImportance用于cv验证验证集的重要性,或者交叉验证应该仅使用RFECV? (在示例中,我cv=3在两种情况下都使用了,但不确定这是否是正确的做法)
如果我运行eli5.show_weights(perm),我会得到:AttributeError: 'PermutationImportance' object has no attribute 'feature_importances_'。这是因为我适合使用吗RFECV?我正在做的事情与这里的最后一个片段类似: https: //eli5.readthedocs.io/en/latest/blackbox/permutation_importance.html
cv作为一个不太重要的问题,当我设置时,这给了我一个警告eli5.sklearn.PermutationImportance:
.../lib/python3.8/site-packages/sklearn/utils/validation.py:68: FutureWarning: Pass …
python ×3
scikit-learn ×3
pandas ×2
pipeline ×2
apache-spark ×1
data-science ×1
dataframe ×1
eli5 ×1
h2o ×1
installation ×1
nlp ×1
numpy ×1
pca ×1
pyspark ×1
r ×1
tf-idf ×1
weka ×1
yellowbrick ×1
zipcode ×1