@@ -172,34 +172,36 @@ __verbose__ : int, default=0
172
172
173
173
## Examples ##
174
174
175
- import pandas as pd
176
- from sklearn.ensemble import RandomForestClassifier
177
- from boruta import BorutaPy
178
-
179
- # load X and y
180
- # NOTE BorutaPy accepts numpy arrays only, hence the .values attribute
181
- X = pd.read_csv('examples/test_X.csv', index_col=0).values
182
- y = pd.read_csv('examples/test_y.csv', header=None, index_col=0).values
183
- y = y.ravel()
184
-
185
- # define random forest classifier, with utilising all cores and
186
- # sampling in proportion to y labels
187
- rf = RandomForestClassifier(n_jobs=-1, class_weight='balanced', max_depth=5)
188
-
189
- # define Boruta feature selection method
190
- feat_selector = BorutaPy(rf, n_estimators='auto', verbose=2, random_state=1)
191
-
192
- # find all relevant features - 5 features should be selected
193
- feat_selector.fit(X, y)
194
-
195
- # check selected features - first 5 features are selected
196
- feat_selector.support_
197
-
198
- # check ranking of features
199
- feat_selector.ranking_
200
-
201
- # call transform() on X to filter it down to selected features
202
- X_filtered = feat_selector.transform(X)
175
+ ``` python
176
+ import pandas as pd
177
+ from sklearn.ensemble import RandomForestClassifier
178
+ from boruta import BorutaPy
179
+
180
+ # load X and y
181
+ # NOTE BorutaPy accepts numpy arrays only, hence the .values attribute
182
+ X = pd.read_csv(' examples/test_X.csv' , index_col = 0 ).values
183
+ y = pd.read_csv(' examples/test_y.csv' , header = None , index_col = 0 ).values
184
+ y = y.ravel()
185
+
186
+ # define random forest classifier, with utilising all cores and
187
+ # sampling in proportion to y labels
188
+ rf = RandomForestClassifier(n_jobs = - 1 , class_weight = ' balanced' , max_depth = 5 )
189
+
190
+ # define Boruta feature selection method
191
+ feat_selector = BorutaPy(rf, n_estimators = ' auto' , verbose = 2 , random_state = 1 )
192
+
193
+ # find all relevant features - 5 features should be selected
194
+ feat_selector.fit(X, y)
195
+
196
+ # check selected features - first 5 features are selected
197
+ feat_selector.support_
198
+
199
+ # check ranking of features
200
+ feat_selector.ranking_
201
+
202
+ # call transform() on X to filter it down to selected features
203
+ X_filtered = feat_selector.transform(X)
204
+ ```
203
205
204
206
## References ##
205
207
0 commit comments