Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scikit-learn
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ian Johnson
scikit-learn
Commits
69e22c77
Commit
69e22c77
authored
15 years ago
by
Fabian Pedregosa
Browse files
Options
Downloads
Patches
Plain Diff
Add docstring to UnivariateFilter.
parent
dca0ff8f
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/plot_feature_selection.py
+3
-19
3 additions, 19 deletions
examples/plot_feature_selection.py
with
3 additions
and
19 deletions
examples/plot_feature_selection.py
+
3
−
19
View file @
69e22c77
...
...
@@ -45,15 +45,15 @@ x_indices = np.arange(x.shape[-1])
################################################################################
# Univariate feature selection
from
scikits.learn.feature_selection
import
univ_selection
from
scikits.learn.feature_selection
import
univ
ariate
_selection
as
univ_selection
# As a scoring function, we use a F test for classification
# We use the default selection function: the 10% most significant
# features
selector
=
univ_selection
.
Univ
Select
ion
(
selector
=
univ_selection
.
Select
Fpr
(
score_func
=
univ_selection
.
f_classif
)
selector
.
fit
(
x
,
y
)
scores
=
-
np
.
log
(
selector
.
p
_values
_
)
scores
=
-
np
.
log
(
selector
.
_
p
values
)
scores
/=
scores
.
max
()
pl
.
bar
(
x_indices
-
.
45
,
scores
,
width
=
.
3
,
label
=
r
'
Univariate score ($-\log(p\,values)$)
'
,
...
...
@@ -69,22 +69,6 @@ svm_weights /= svm_weights.max()
pl
.
bar
(
x_indices
-
.
15
,
svm_weights
,
width
=
.
3
,
label
=
'
SVM weight
'
,
color
=
'
r
'
)
################################################################################
# Now fit an SVM with added feature selection
selector
=
univ_selection
.
UnivSelection
(
estimator
=
clf
,
score_func
=
univ_selection
.
f_classif
)
selector
.
fit
(
x
,
y
)
svm_weights
=
(
clf
.
support_
**
2
).
sum
(
axis
=
0
)
svm_weights
/=
svm_weights
.
max
()
full_svm_weights
=
np
.
zeros
(
selector
.
support_
.
shape
)
full_svm_weights
[
selector
.
support_
]
=
svm_weights
pl
.
bar
(
x_indices
+
.
15
,
full_svm_weights
,
width
=
.
3
,
label
=
'
SVM weight after univariate selection
'
,
color
=
'
b
'
)
pl
.
title
(
"
Comparing feature selection
"
)
pl
.
xlabel
(
'
Feature number
'
)
pl
.
yticks
(())
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment