Skip to content

Commit 4f4aa9c

Browse files
OkonSamuelablaom
andauthored
Traits (#18)
* remove dependence of is_wrapper trait on base model. * bug fixes and doc build * fix typo in docstring Co-authored-by: Anthony Blaom, PhD <[email protected]> --------- Co-authored-by: Anthony Blaom, PhD <[email protected]>
1 parent 1a09689 commit 4f4aa9c

File tree

6 files changed

+305
-173
lines changed

6 files changed

+305
-173
lines changed

README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
11
# FeatureSelection.jl
22

3-
| Linux | Coverage | Code Style
4-
| :------------ | :------- | :------------- |
5-
| [![Build Status](https://github.com/JuliaAI/FeatureSelection.jl/workflows/CI/badge.svg)](https://github.com/JuliaAI/FeatureSelection.jl/actions) | [![Coverage](https://codecov.io/gh/JuliaAI/FeatureSelection.jl/branch/master/graph/badge.svg)](https://codecov.io/github/JuliaAI/FeatureSelection.jl?branch=dev) | [![Code Style: Blue](https://img.shields.io/badge/code%20style-blue-4495d1.svg)](https://github.com/invenia/BlueStyle) |
3+
| Linux | Coverage | Documentation | Code Style
4+
| :------------ | :------- | :------------- | :------------- |
5+
| [![Build Status](https://github.com/JuliaAI/FeatureSelection.jl/workflows/CI/badge.svg)](https://github.com/JuliaAI/FeatureSelection.jl/actions) | [![Coverage](https://codecov.io/gh/JuliaAI/FeatureSelection.jl/branch/master/graph/badge.svg)](https://codecov.io/github/JuliaAI/FeatureSelection.jl?branch=dev) | [![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://juliaai.github.io/FeatureSelection.jl/dev/) | [![Code Style: Blue](https://img.shields.io/badge/code%20style-blue-4495d1.svg)](https://github.com/invenia/BlueStyle) |
66

77
Repository housing feature selection algorithms for use with the machine learning toolbox [MLJ](https://juliaai.github.io/MLJ.jl/dev/).
8+
9+
This package provides a collection of feature selection algorithms designed for use with MLJ, a powerful machine learning toolbox in Julia. It aims to facilitate the process of selecting the most relevant features from your datasets, enhancing the performance and interpretability of your machine learning models.
10+
11+
## Key Features
12+
- Integration with MLJ: Seamlessly integrates with MLJ's extensive suite of tools and models.
13+
- Variety of Algorithms: Includes multiple feature selection algorithms to suit different types of data and models.
14+
- User-friendly: Easy to use with clear documentation and examples.
15+
16+
## Getting Started
17+
To get started with this package, refer to the documentation for installation instructions, usage guides, and API references.
18+
19+
## Contributing
20+
Contributions are welcome! Please refer to MLJ contributing [guidelines](https://github.com/JuliaAI/MLJ.jl/blob/dev/CONTRIBUTING.md) for more information.
21+
22+
## License
23+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
24+

docs/make.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ makedocs(;
3030
deploydocs(;
3131
deploy_config = Documenter.GitHubActions(),
3232
repo="github.com/JuliaAI/FeatureSelection.jl.git",
33+
devbranch="dev",
3334
push_preview=true
3435
)

docs/src/api.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,9 @@ CurrentModule = FeatureSelection
66
```@docs
77
FeatureSelector
88
RecursiveFeatureElimination
9+
```
10+
# Internal Utils
11+
```@docs
12+
abs_last
13+
score_features!
914
```

docs/src/index.md

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ end
5252
```
5353
```@example example1
5454
using MLJ, FeatureSelection, StableRNGs
55-
rng = StableRNG(10)
55+
rng = StableRNG(123)
5656
A = rand(rng, 50, 10)
5757
X = MLJ.table(A) # features
58-
y = @views(
59-
10 .* sin.(
60-
pi .* A[:, 1] .* A[:, 2]
61-
) .+ 20 .* (A[:, 3] .- 0.5).^ 2 .+ 10 .* A[:, 4] .+ 5 * A[:, 5]
58+
y = @views(
59+
10 .* sin.(
60+
pi .* A[:, 1] .* A[:, 2]
61+
) + 20 .* (A[:, 3] .- 0.5).^ 2 .+ 10 .* A[:, 4] .+ 5 * A[:, 5]
6262
) # target
6363
```
6464
Now we that we have our data, we can create our recursive feature elimination model and
@@ -74,51 +74,49 @@ fit!(mach)
7474
```
7575
We can inspect the feature importances in two ways:
7676
```jldoctest
77-
julia> report(mach).ranking
78-
10-element Vector{Int64}:
79-
1
80-
1
81-
1
82-
1
83-
1
84-
2
85-
3
86-
4
87-
5
88-
6
77+
julia> report(mach).scores
78+
Dict{Symbol, Int64} with 10 entries:
79+
:x9 => 4
80+
:x2 => 6
81+
:x5 => 6
82+
:x6 => 3
83+
:x7 => 2
84+
:x3 => 6
85+
:x8 => 1
86+
:x4 => 6
87+
:x10 => 5
88+
:x1 => 6
8989
9090
julia> feature_importances(mach)
9191
10-element Vector{Pair{Symbol, Int64}}:
92-
:x1 => 6
93-
:x2 => 5
94-
:x3 => 4
95-
:x4 => 3
96-
:x5 => 2
97-
:x6 => 1
98-
:x7 => 1
92+
:x9 => 4
93+
:x2 => 6
94+
:x5 => 6
95+
:x6 => 3
96+
:x7 => 2
97+
:x3 => 6
9998
:x8 => 1
100-
:x9 => 1
101-
:x10 => 1
99+
:x4 => 6
100+
:x10 => 5
101+
:x1 => 6
102102
```
103-
Note that a variable with lower rank has more significance than a variable with higher rank; while a variable with higher feature importance is better than a variable with lower feature importance.
104-
105103
We can view the important features used by our model by inspecting the `fitted_params`
106104
object.
107105
```jldoctest
108106
julia> p = fitted_params(mach)
109-
(features_left = [:x1, :x2, :x3, :x4, :x5],
107+
(features_left = [:x4, :x2, :x1, :x5, :x3],
110108
model_fitresult = (forest = Ensemble of Decision Trees
111109
Trees: 100
112-
Avg Leaves: 25.26
113-
Avg Depth: 8.36,),)
110+
Avg Leaves: 25.3
111+
Avg Depth: 8.01,),)
114112
115113
julia> p.features_left
116114
5-element Vector{Symbol}:
117-
:x1
118-
:x2
119-
:x3
120115
:x4
116+
:x2
117+
:x1
121118
:x5
119+
:x3
122120
```
123121
We can also call the `predict` method on the fitted machine, to predict using a
124122
random forest regressor trained using only the important features, or call the `transform`
@@ -157,16 +155,16 @@ julia> fitted_params(self_tuning_rfe_mach).best_fitted_params.features_left
157155
158156
julia> feature_importances(self_tuning_rfe_mach)
159157
10-element Vector{Pair{Symbol, Int64}}:
160-
:x1 => 6
161-
:x2 => 5
162-
:x3 => 4
163-
:x4 => 3
164-
:x5 => 2
165-
:x6 => 1
158+
:x9 => 2
159+
:x2 => 6
160+
:x5 => 6
161+
:x6 => 4
166162
:x7 => 1
167-
:x8 => 1
168-
:x9 => 1
169-
:x10 => 1
163+
:x3 => 6
164+
:x8 => 5
165+
:x4 => 6
166+
:x10 => 3
167+
:x1 => 6
170168
```
171169
and call `predict` on the tuned model machine as shown below
172170
```@example example1

0 commit comments

Comments
 (0)