标签: feature-selection

使用weka对传感器数据进行分类

我正在研究一个分类问题,它有不同的传感器.每个传感器收集一组数值.

我认为这是一个分类问题,并希望使用weka作为此问题的ML工具.但我不确定如何使用weka来处理输入值?哪个分类器最适合这个问题(一个特征的实例是一组数值)?

例如,我有三个传感器A,B,C.我可以将所有传感器中的5个采集数据定义为一个实例吗?例如,A的一个实例是{1,2,3,4,5,6,7},B的一个实例是{3,434,534,213,55,4,7).13 C {424,24,24,13,24,5,6}.

非常感谢您抽出时间审阅我的问题.

classification machine-learning weka feature-selection

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

python:如何从feature_importances获取真正的功能名称

我使用Python的sklearn随机林(ensemble.RandomForestClassifier)进行分类,并feature_importances_用于查找分类器的重要功能.现在我的代码是:

for trip in database:
    venue_feature_start.append(Counter(trip['POI']))
# Counter(trip['POI']) is like Counter({'school':1, 'hospital':1, 'bus station':2}),actually key is the feature

feat_loc_vectorizer = DictVectorizer()
feat_loc_vectorizer.fit(venue_feature_start)
feat_loc_orig_mat = feat_loc_vectorizer.transform(venue_feature_start)

orig_tfidf = TfidfTransformer()
orig_ven_feat = orig_tfidf.fit_transform(feat_loc_orig_mat.tocsr())

# so DictVectorizer() and TfidfTransformer() help me to phrase the features and for each instance, the feature dimension is 580, which means that there are 580 venue types 

data = orig_ven_feat.tocsr()

le = LabelEncoder() 
labels = le.fit_transform(labels_raw)
if "Unlabelled" in labels_raw:
    unlabelled_int = …
Run Code Online (Sandbox Code Playgroud)

python classification feature-selection scikit-learn

1
推荐指数
2
解决办法
5247
查看次数

SciKit使用RFECV学习特征选择和交叉验证

我仍然是机器学习的新手,并试图自己解决问题.我正在使用SciKit学习并拥有大约20,000个功能的推文数据集(n_features = 20,000).到目前为止,我的精确度,召回率和f1得分都达到了79%左右.我想使用RFECV进行特征选择并提高模型的性能.我已经阅读了SciKit学习文档,但对如何使用RFECV仍然有点困惑.

这是我到目前为止的代码:

from sklearn.feature_extraction.text import CountVectorizer
from sklearn.feature_extraction.text import TfidfTransformer
from sklearn.naive_bayes import MultinomialNB
from sklearn.cross_validation import StratifiedShuffleSplit
from sklearn.cross_validation import cross_val_score
from sklearn.feature_selection import RFECV
from sklearn import metrics

# cross validation
sss = StratifiedShuffleSplit(y, 5, test_size=0.2, random_state=42)
for train_index, test_index in sss:
    docs_train, docs_test = X[train_index], X[test_index]
    y_train, y_test = y[train_index], y[test_index]

# feature extraction
count_vect = CountVectorizer(stop_words='English', min_df=3, max_df=0.90, ngram_range=(1,3))
X_CV = count_vect.fit_transform(docs_train)

tfidf_transformer = TfidfTransformer()
X_tfidf = tfidf_transformer.fit_transform(X_CV)

# Create the RFECV object
nb …
Run Code Online (Sandbox Code Playgroud)

machine-learning feature-selection scikit-learn cross-validation naivebayes

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

值:错误无法在使用 Sklearn 功能相关性时将字符串转换为浮点数

您好,我已经训练并测试了数据。我正在尝试使用sklearn的特征相关性Seelct K Best来选择相关特征并在之后绘制条形图。但是我收到这个错误:

ValueError: could not convert string to float: B
Run Code Online (Sandbox Code Playgroud)

但我开始认为我的数据集中确实有一列看起来像这样,这可能是问题所在:

CancellationCode:
A
B
C
D
Run Code Online (Sandbox Code Playgroud)

如果此列导致问题,我该如何解决此错误 这是我的代码如下:

import numpy as np
from sklearn.feature_selection import SelectKBest, f_classif
import matplotlib.pyplot as plt

selector = SelectKBest(f_classif, k=13)
selector.fit(X_train, y_train)

scores_select = selector.pvalues_
print scores_select


# Plotting the bar Graph to visually see the weight of each feature
plt.bar(range(len(scores_select)), scores_select, align='center')
plt.xticks(range(len(features_columns)), features_columns, rotation='vertical')
plt.show()
Run Code Online (Sandbox Code Playgroud)

python ipython feature-selection scikit-learn

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

为什么我们使用相关系数进行特征选择?

我正在学习特征选择。我发现了这一点,并看到许多内核检查相关系数矩阵。(在上面的链接中,他们介绍了 3 种特征选择方法,首先是过滤方法,包括相关系数和卡方检验。)

为什么我们可以使用相关系数进行特征选择?

我认为它只能表示 2 个变量之间的线性关系,因此它不能表示 2 个或多个变量的组合或非线性关系的影响。

所以我想知道相关系数是否适用于特征选择。为什么以及如何将其用于特征选择?

machine-learning feature-selection

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

R在RFE(递归特征消除)中使用我自己的模型来选择重要特征

使用 RFE,您可以获得特征的重要性等级,但现在我只能使用包内的模型和参数,例如:lmFuncs(linear model),rfFuncs(random forest) 似乎

caretFuncs
Run Code Online (Sandbox Code Playgroud)

可以对自己的模型和参数做一些自定义设置,但是我不知道细节,正式文档没有给出细节,我想在这个RFE过程中应用svm和gbm,因为这是我当前使用的模型训练,有人知道吗?

r svm feature-selection rfe r-caret

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

SelectKBest用于回归给出“未知标签类型”-错误

我正在尝试使用SelectKBest示例的稍作修改的版本,但仍在继续获取ValueError(“ Unknown label type:%s”%repr(ys))

这是我的代码:

# Importing dependencies
import numpy as np
from sklearn.feature_selection import SelectKBest
from sklearn.feature_selection import chi2
from sklearn.datasets import load_iris

#The Example from:
#http://scikit-learn.org/stable/modules/feature_selection.html#univariate-feature-selection
iris = load_iris()
X, Y = iris.data, iris.target
print(X.shape, type(X), type(X[0,0]))
print(Y.shape, type(Y), type(Y[0]))
X_new = SelectKBest(chi2, k=2).fit_transform(X, Y)

#My toyproblem:
X = np.random.uniform(0,1, size=(5000, 10))
Y = np.random.uniform(0,1, size=(5000,))

#Type cast which might solve my problem by thi suggestion:
# /sf/ask/3174258531/
X=X.astype('float')
Y=Y.astype('float')

print(X.shape, type(X), type(X[0,0]))
print(Y.shape, type(Y), type(Y[0]))

X_new = …
Run Code Online (Sandbox Code Playgroud)

python feature-selection scikit-learn

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

如何从 Tidymodels ranger 对象获取变量/特征重要性?

我有一个来自 tidymodels rand_forest 函数的 Ranger 对象:

rf <- rand_forest(mode = "regression", trees = 1000) %>% fit(pay_rate ~ age+profession)
Run Code Online (Sandbox Code Playgroud)

我想获得每个变量的特征重要性(我有比这个例子更多的特征)。我尝试过诸如rf$variable.importance, 或 之类的东西importance(rf),但前者返回NULL而后者函数不存在。我尝试使用该vip包,但这不适用于游侠对象。如何从该对象中提取特征重要性?

r dataframe feature-selection tidyverse tidymodels

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

如何使用 tidymodels 进行特征选择

我有一个在 tidymodels (R) 中创建的逻辑回归模型。我正在尝试进行功能选择。如何使用 CRAN 上发布的包(请不要使用开发包)在 tidymodels 框架中进行功能选择?

每个人都说要做正则化逻辑回归,但我需要能够进行推理/具有参数置信区间,这是正则化无法做到的。

r feature-selection tidymodels

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

确定每个类最重要的特征

想象一个机器学习问题,其中有 20 个类和大约 7000 个稀疏布尔特征。

我想弄清楚每个类的 20 个最独特的功能是什么。换句话说,在特定类中经常使用但在其他类中未使用或几乎不使用的功能。

什么是可以做到这一点的好的特征选择算法或启发式方法?

machine-learning feature-selection

0
推荐指数
1
解决办法
2169
查看次数

计算 VIF(方差通货膨胀因子)时出错

在 Rstudio 的小数据集上计算 VIF 时出现以下错误。有人可以帮忙吗?如果需要,我可以提供有关数据集的更多信息。

“as.vector(y) 中的错误 - 二元运算符的 mean(y) 非数字参数”。

数据集:80 个观察。和 15 个变量(所有变量都是数字)

步骤如下:

   # 1. Determine correlation  
    library(corrplot)  
    cor.data <- cor(train)  
    corrplot(cor.data, method = 'color')  
    cor.data    


# 2. Build Model  

    model2 <- lm(Volume~., train)  
    summary(model2)  

# 3. Calculate VIF  

    library(VIF)  
    vif(model2) 
Run Code Online (Sandbox Code Playgroud)

这是一个包含 20 个 obs 的示例数据集。

train <- structure(list(Price = c(949, 2249.99, 399, 409.99, 1079.99, 
114.22, 379.99, 65.29, 119.99, 16.99, 6.55, 15, 52.5, 21.08, 
18.98, 3.6, 3.6, 174.99, 9.99, 670), X.5.Star.Reviews. = c(3, 
2, 3, 49, 58, …
Run Code Online (Sandbox Code Playgroud)

r variance predict feature-selection

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

有什么方法可以从 R 中的累积 PCA 图中选择前 n 个 PCA 组件?

我有兴趣从我的数据集的累积 PCA 图中选取前 10 个 PCA 组件。我设法获得了 PCA 图,例如碎石图、配对图等,但对我来说没有多大意义。所以我想从它的累积 PCA 图中选择前 10 个 PCA 图并且我做到了,但是我需要使用这个前 10 个 PCA 组件来对我的原始数据集进行子集化。谁能指出我如何使尝试更准确和更可取?

可重复数据

persons_df <- data.frame(person1=sample(1:200,20, replace = FALSE),
                    person2=as.factor(sample(20)),
                    person3=sample(1:250,20, replace = FALSE),
                    person4=sample(1:300,20, replace = FALSE),
                    person5=as.factor(sample(20)),
                    person6=as.factor(sample(20)))

row.names(persons_df) <-letters[1:20]
Run Code Online (Sandbox Code Playgroud)

我的尝试

my_pca <- prcomp(t(persons_df), center=TRUE, scale=FALSE)
summary(my_pca)

my_pca_proportionvariances <- cumsum(((my_pca$sdev^2) / (sum(my_pca$sdev^2)))*100)
Run Code Online (Sandbox Code Playgroud)

公共数据集

由于我在创建上述可复制数据时遇到了一些问题,因此我在这里链接了公共示例数据集

在这里,我需要为 选择前 10 个 PCA 组件persons_df,然后对原始数据进行子集化,然后对其运行简单的线性回归。我怎样才能在这里完成我的方法以实现我的目标?有人能在这里快速指出我吗?任何的想法?

r pca feature-selection

0
推荐指数
1
解决办法
745
查看次数