|
29 | 29 | - [Introduction to arrays using numpy](#introduction-to-arrays-using-numpy)
|
30 | 30 | - [visualize a dataset using seaborn](#visualize-a-dataset-using-seaborn)
|
31 | 31 | - [manipulate dataset with pandas](#manipulate-dataset-with-pandas)
|
32 |
| -- [iris flowers classification with python](#iris-flowers-classification-with-python) |
| 32 | +- [iris flowers classification](#iris-flowers-classification) |
33 | 33 | - [iris flowers data set](#iris-flowers-data-set)
|
34 | 34 | - [Load the dataset](#load-the-dataset)
|
35 | 35 | - [Examine the dataset](#examine-the-dataset)
|
|
40 | 40 | - [Fit the model](#fit-the-model)
|
41 | 41 | - [Evaluate the trained model performance](#evaluate-the-trained-model-performance)
|
42 | 42 | - [Use k-Fold Cross-Validation to better evaluate the trained model performance](#use-k-Fold-cross-validation-to-better-evaluate-the-trained-model-performance)
|
43 |
| - - [Use the model with unseen data and make predictions](#use-the-model-with-unseen-data-and-make-predictions) |
| 43 | + - [Use the model with unseen data and make predictions](#use-the-model-with-unseen-data-and-make-predictions) |
| 44 | +-[Remove irrelevant features to reduce overfitting](#remove-irrelevant-features-to-reduce-overfitting) |
| 45 | + -[Recursive Feature Elimination](#recursive-feature-elimination) |
| 46 | + |
44 | 47 |
|
45 | 48 | # What to find in this repository
|
46 | 49 |
|
@@ -184,6 +187,16 @@ Detecting overfitting is useful, but it doesn’t solve the problem.
|
184 | 187 |
|
185 | 188 | To prevent overfitting, train your algorithm with more data. It won’t work every time, but training with more data can help algorithms detect the signal and the noise better. Of course, that’s not always the case. If we just add more noisy data, this technique won’t help. That’s why you should always ensure your data is clean and relevant.
|
186 | 189 |
|
| 190 | +To prevent overfitting, improve the data by removing irrelevant features. |
| 191 | +Not all features contribute to the prediction. Removing features of low importance can improve accuracy, and reduce overfitting. Training time can also be reduced. |
| 192 | +Imagine a dataset with 300 columns and only 250 rows. That is a lot of features for only very few training samples. So, instead of using all features, it’s better to use only the most important ones. This will make the training process faster. It can help to prevent overfitting because the model doesn’t need to use all the features. |
| 193 | +So, rank the features and elimate the less importantes ones. |
| 194 | + |
| 195 | +The python library `scikit-learn` provides a `feature selection` module which helps identify the most relevant features of a dataset. |
| 196 | +Examples: |
| 197 | +- The class `VarianceThreshold` removes the features with low variance. It removes the features with a variance lower than a configurable threshold. |
| 198 | +- The class `RFE` (Recursive Feature Elimination) recursively removes features. It selects features by recursively considering smaller and smaller sets of features. It first trains the classifier on the initial set of features. it trains a classifier multiple times using smaller and smaller features set. After each training, the importance of the features is calculated and the least important feature is eliminated from current set of features. That procedure is recursively repeated until the desired number of features to select is eventually reached. RFE is able to find out the combination of features that contribute to the prediction. You just need to import RFE from sklearn.feature_selection and indicate the number of features to select and which classifier model to use. |
| 199 | + |
187 | 200 | # Python libraries
|
188 | 201 |
|
189 | 202 | ## scikit-learn
|
@@ -698,7 +711,7 @@ male (0, 18] 0.800000 1.000000 1.000000
|
698 | 711 | ```
|
699 | 712 |
|
700 | 713 |
|
701 |
| -# iris flowers classification with python |
| 714 | +# iris flowers classification |
702 | 715 |
|
703 | 716 | The demo is about iris flowers classification.
|
704 | 717 |
|
@@ -1320,11 +1333,17 @@ so the model prediction is:
|
1320 | 1333 | - the first two flowers belong to the iris setosa category
|
1321 | 1334 | - the last 2 ones belong to the iris virginica category
|
1322 | 1335 |
|
1323 |
| -# |
| 1336 | +# Remove irrelevant features to reduce overfitting |
| 1337 | + |
| 1338 | +To prevent overfitting, improve the data by removing irrelevant features. |
| 1339 | + |
| 1340 | +## Recursive Feature Elimination |
| 1341 | + |
| 1342 | +The class `RFE` (Recursive Feature Elimination) from the `feature selection` module from the python library scikit-learn recursively removes features. It selects features by recursively considering smaller and smaller sets of features. It first trains the classifier on the initial set of features. It trains a classifier multiple times using smaller and smaller features set. After each training, the importance of the features is calculated and the least important feature is eliminated from current set of features. That procedure is recursively repeated until the desired number of features to select is eventually reached. RFE is able to find out the combination of features that contribute to the prediction. You just need to import RFE from sklearn.feature_selection and indicate which classifier model to use and the number of features to select. |
1324 | 1343 |
|
1325 |
| -Let's use RFE (Recursive Feature Elimination) with Scikit Learn to select the features to keep |
| 1344 | +Here's how you can use the class `RFE` in order to find out the combination of important features. |
1326 | 1345 |
|
1327 |
| -We will use this example [recursive_feature_elimination.py](recursive_feature_elimination.py) |
| 1346 | +We will use this basic example [recursive_feature_elimination.py](recursive_feature_elimination.py) |
1328 | 1347 |
|
1329 | 1348 | Load LinearSVC class from Scikit Learn library
|
1330 | 1349 | LinearSVC is similar to SVC with parameter kernel='linear'
|
|
0 commit comments