Guest User

Untitled

a guest
Jul 18th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. from sklearn.feature_selection import SelectKBest
  2. from scipy.stats import pearsonr
  3. #Select K best features, return the data after selecting the feature
  4. The first parameter is a function to calculate whether the evaluation feature is good. The function inputs the feature matrix and the target vector, and outputs an array of two groups (score, P value). The i-th item of the array is the score and P value of the i-th feature. . Defined here as the correlation coefficient
  5. #Parameter k is the number of features selected
  6. SelectKBest(lambda X, Y: array(map(lambda x:pearsonr(x, Y), X.T)).T, k=2).fit_transform(iris.data, iris.target)
Add Comment
Please, Sign In to add comment