Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sklearn.feature_selection import SelectKBest
- from scipy.stats import pearsonr
- #Select K best features, return the data after selecting the feature
- 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
- #Parameter k is the number of features selected
- 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