2017-11-08 7 views
-3

私はPythonとMachine Learningの新機能です。クラス属性Python scikitで上位n個の相関フィーチャ(Pearson cofficientに基づいて)を見つけるlearn

私はいくつかの機能を備えたデータセットを持っています。私はピアソン係数を使ってクラス属性を持つ上位n個の相関属性/特徴を見つけたいと思っています。どうやってやるの。

以下は私のデータセットの構造である: class_attr COL1 COL2 col3という...コルン

答えて

0

あなたは、あなたの質問に掲載している内容から判断すると、私は分類問題ではなく回帰一つであることが、これを想定しています。その場合、ピアソン係数を相関のメトリックとして使用することは現実的ではありません。

Recursive Feature Elimination with Cross Validation (RFECV)を使用すると、最適な数の機能とそれに対応する機能の重要性を得ることができます。 example on this linkに基づいてこのコードをチェックしてください。

import matplotlib.pyplot as plt 
from sklearn.svm import SVC 
from sklearn.cross_validation import StratifiedKFold 
from sklearn.feature_selection import RFECV 
svc = SVC(kernel="linear") 
rfecv = RFECV(estimator=svc, step=1, cv=StratifiedKFold(labels, 50), 
     scoring='precision') 
rfecv.fit(features, labels) 
print("Optimal number of features : %d" % rfecv.n_features_) 
print rfecv.support_ 
features=features[:,rfecv.support_] 
# Plot number of features VS. cross-validation scores 
plt.figure() 
plt.xlabel("Number of features selected") 
plt.ylabel("Cross validation score (nb of correct classifications)") 
plt.plot(range(1, len(rfecv.grid_scores_) + 1), rfecv.grid_scores_) 
plt.show() 

サンプル出力:またenter image description here

、カスタムスコアリング機能を指定し、.scores_属性を使用して特徴のそれぞれのスコアを取得するためにselectKbest Methodを使用することができます。

This is a good blog post Scikit-learnの機能選択に関する。

Here is another blog postこれらの例に加えて、複数の方法があります。

さらに、そのようなAPIについてはofficial documentationをご覧ください。

関連する問題