Machine learning projects
In this projects I try to find best hyperparametres for classification and regression models.
I used Grid search for finding best hyperparametres and find them.
I train my models and calculate metrics.
For finding metrics for each models I used sklearn library and try write code to find them by formula.
These tables illustrates output from calculation of metrics.
Table #1 Classification metrics by sklearn library
+-----------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ | Model | Accuracy | AUC | Precision | Recall | F1 Score | +-----------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ | SVM Classifier | 0.8760633143103262 | 0.9646649510457755 | 0.8750126878080591 | 0.8760633143103262 | 0.875156182836102 | | KNN | 0.894260794659201 | 0.967623767098142 | 0.8943273293995365 | 0.894260794659201 | 0.8942361800895275 | | Random Forest | 0.8054269408851082 | 0.9174209530039589 | 0.8054777458023261 | 0.8054269408851082 | 0.7981483795441057 | | Gradient Boost | 0.9247334984386777 | 0.9843829128160531 | 0.924524980577963 | 0.9247334984386777 | 0.9245689889939814 | | Extra Tree Classifier | 0.9216108538817702 | 0.9838468565217876 | 0.9212279118226688 | 0.9216108538817702 | 0.9212318552863391 | +-----------------------+--------------------+--------------------+--------------------+--------------------+--------------------+
Table #2 Classification metrics by formula
Metrics by formula +-----------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ | Model | Confusion matrix | Accuracy | AUC | Precision | Recall | F1 Score | +-----------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ | SVM Classifier | [[2292 23 617] | 0.8760633143103262 | 0.9646649510457834 | 0.8883377378307943 | 0.8872419831038393 | 0.8874095197261721 | | | [ 4 1858 15] | | | | | | | | [ 455 37 3986]] | | | | | | | KNN | [[2582 50 300] | 0.894260794659201 | 0.967674409881321 | 0.8920739791322251 | 0.896350866122195 | 0.8941260672867964 | | | [ 21 1714 142] | | | | | | | | [ 296 173 4009]] | | | | | | | Random Forest | [[1640 14 1278] | 0.8054269408851082 | 0.9174160182467035 | 0.8365902657640992 | 0.8147794858233706 | 0.818860438163068 | | | [ 0 1877 0] | | | | | | | | [ 515 0 3963]] | | | | | | | Gradient Boost | [[2549 2 381] | 0.9247334984386777 | 0.9843829128160749 | 0.9349245442236377 | 0.9329350748370945 | 0.9338745823641651 | | | [ 0 1877 0] | | | | | | | | [ 316 0 4162]] | | | | | | | Extra Tree Classifier | [[2522 12 398] | 0.9216108538817702 | 0.9838452811047055 | 0.9301256338765577 | 0.9287882685568274 | 0.9292711234162621 | | | [ 2 1868 7] | | | | | | | | [ 285 24 4169]] | | | | | | +-----------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+
Table #3 Regression Metrics by Sklearn library
+---------------------------+---------------------+---------------------+---------------------+---------------------+--------------------+ | Model | MAE | MSE | R2_score | Adjusted R2 | MAPE | +---------------------------+---------------------+---------------------+---------------------+---------------------+--------------------+ | Linear Rregression | 0.6790619544801199 | 0.6053479986771267 | 0.21401496209909776 | 0.21316763023417662 | 1233615611858540.8 | | Random Forest Regressor | 0.32626251749757723 | 0.27897839991385803 | 0.6377738941749109 | 0.6373833960013178 | 729018674255937.0 | | Gradient Boosts Regressor | 0.3354998105378756 | 0.26473187569303896 | 0.6562716093802585 | 0.6559010526848944 | 709630439051149.6 | | Ridge Regression | 0.6790674749627736 | 0.6053466079338703 | 0.21401676784289048 | 0.21316943792465304 | 1233631632055052.5 | | SVM Regressor | 0.6776849176329902 | 0.6079680912656933 | 0.21061302870371412 | 0.2097620293814887 | 1192119475020674.0 | | XG Boosts | 0.46206925707994134 | 0.40268939180902946 | 0.47714729779403053 | 0.47658363597621467 | 1000768920327548.8 | +---------------------------+---------------------+---------------------+---------------------+---------------------+--------------------+
Table #4 Regression Metrics by formula.
+---------------------------+--------+--------+----------+-------------+----------+ | Model | MAE | MSE | R2_score | Adjusted R2 | MAPE | +---------------------------+--------+--------+----------+-------------+----------+ | Linear Rregression | 0.6791 | 0.6053 | 0.214 | 0.2132 | 138.3684 | | Random Forest Regressor | 0.3263 | 0.279 | 0.6378 | 0.6374 | 43.958 | | Gradient Boosts Regressor | 0.3355 | 0.2647 | 0.6563 | 0.6559 | 45.7152 | | Ridge Regression | 0.6791 | 0.6053 | 0.214 | 0.2132 | 138.3698 | | SVM Regressor | 0.6777 | 0.608 | 0.2106 | 0.2097 | 137.6117 | | XG Boosts | 0.4621 | 0.4027 | 0.4771 | 0.4765 | 64.4678 | +---------------------------+--------+--------+----------+-------------+----------+