{"cells":[{"cell_type":"code","execution_count":null,"metadata":{"id":"Dashzl3dRwP7"},"outputs":[],"source":["import pandas as pd\n","import numpy as np\n","from sklearn.model_selection import train_test_split\n","from sklearn.preprocessing import StandardScaler, OneHotEncoder\n","from sklearn.metrics import mean_squared_error\n","from xgboost import XGBRegressor\n","import shap\n","import joblib\n","from sklearn.model_selection import GridSearchCV\n","from sklearn.metrics import make_scorer\n","from sklearn.metrics import mean_squared_error\n","from sklearn.linear_model import LinearRegression"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"_Ufhf9j3TLTN"},"outputs":[],"source":["data = pd.read_csv('/content/Final_data.csv')"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":330},"executionInfo":{"elapsed":404,"status":"ok","timestamp":1732487515961,"user":{"displayName":"Monayam Hossain Moin","userId":"10221365783455858880"},"user_tz":-60},"id":"LklutNv6TYKJ","outputId":"de6bb539-8826-4884-9be4-ff1c9945dd8e"},"outputs":[{"data":{"application/vnd.google.colaboratory.intrinsic+json":{"type":"dataframe","variable_name":"data"},"text/html":["\n","
\n"," | Unnamed: 0 | \n","id | \n","funded_amount | \n","loan_amount | \n","activity | \n","sector | \n","country_code | \n","country | \n","region | \n","currency | \n","partner_id | \n","posted_time | \n","disbursed_time | \n","funded_time | \n","term_in_months | \n","lender_count | \n","borrower_genders | \n","repayment_interval | \n","date | \n","funding_days | \n","
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n","0 | \n","653051 | \n","300.0 | \n","300.0 | \n","Fruits & Vegetables | \n","Food | \n","PK | \n","Pakistan | \n","Lahore | \n","PKR | \n","247.0 | \n","2014-01-01 06:12:39+00:00 | \n","2013-12-17 08:00:00+00:00 | \n","2014-01-02 10:06:32+00:00 | \n","12.0 | \n","12 | \n","female | \n","irregular | \n","2014-01-01 | \n","1 | \n","
1 | \n","1 | \n","653053 | \n","575.0 | \n","575.0 | \n","Rickshaw | \n","Transportation | \n","PK | \n","Pakistan | \n","Lahore | \n","PKR | \n","247.0 | \n","2014-01-01 06:51:08+00:00 | \n","2013-12-17 08:00:00+00:00 | \n","2014-01-02 09:17:23+00:00 | \n","11.0 | \n","14 | \n","group | \n","irregular | \n","2014-01-01 | \n","1 | \n","
2 | \n","2 | \n","653068 | \n","150.0 | \n","150.0 | \n","Transportation | \n","Transportation | \n","IN | \n","India | \n","Maynaguri | \n","INR | \n","334.0 | \n","2014-01-01 09:58:07+00:00 | \n","2013-12-17 08:00:00+00:00 | \n","2014-01-01 16:01:36+00:00 | \n","43.0 | \n","6 | \n","female | \n","bullet | \n","2014-01-01 | \n","0 | \n","
3 | \n","3 | \n","653063 | \n","200.0 | \n","200.0 | \n","Embroidery | \n","Arts | \n","PK | \n","Pakistan | \n","Lahore | \n","PKR | \n","247.0 | \n","2014-01-01 08:03:11+00:00 | \n","2013-12-24 08:00:00+00:00 | \n","2014-01-01 13:00:00+00:00 | \n","11.0 | \n","8 | \n","female | \n","irregular | \n","2014-01-01 | \n","0 | \n","
4 | \n","4 | \n","653084 | \n","400.0 | \n","400.0 | \n","Milk Sales | \n","Food | \n","PK | \n","Pakistan | \n","Abdul Hakeem | \n","PKR | \n","245.0 | \n","2014-01-01 11:53:19+00:00 | \n","2013-12-17 08:00:00+00:00 | \n","2014-01-01 19:18:51+00:00 | \n","14.0 | \n","16 | \n","female | \n","monthly | \n","2014-01-01 | \n","0 | \n","
\n"," | count | \n","
---|---|
borrower_genders | \n","\n"," |
female | \n","377749 | \n","
male | \n","103370 | \n","
group | \n","93008 | \n","
\n"," | count | \n","
---|---|
country | \n","\n"," |
Philippines | \n","157532 | \n","
Kenya | \n","61839 | \n","
Cambodia | \n","33439 | \n","
Pakistan | \n","24917 | \n","
Peru | \n","21473 | \n","
... | \n","... | \n","
Benin | \n","2 | \n","
Afghanistan | \n","2 | \n","
Mauritania | \n","1 | \n","
Cote D'Ivoire | \n","1 | \n","
Bhutan | \n","1 | \n","
82 rows × 1 columns
\n","\n"," | count | \n","
---|---|
country | \n","\n"," |
Philippines | \n","157532 | \n","
Kenya | \n","61839 | \n","
Cambodia | \n","33439 | \n","
Pakistan | \n","24917 | \n","
Peru | \n","21473 | \n","
Uganda | \n","18093 | \n","
Tajikistan | \n","17443 | \n","
Colombia | \n","17262 | \n","
El Salvador | \n","16505 | \n","
Ecuador | \n","12867 | \n","
Paraguay | \n","11518 | \n","
India | \n","10868 | \n","
Nicaragua | \n","9906 | \n","
Vietnam | \n","9877 | \n","
Nigeria | \n","9132 | \n","
Bolivia | \n","7511 | \n","
Palestine | \n","7097 | \n","
Armenia | \n","6804 | \n","
Guatemala | \n","6741 | \n","
Samoa | \n","6662 | \n","
Lebanon | \n","6384 | \n","
Mali | \n","6122 | \n","
Honduras | \n","5999 | \n","
Togo | \n","5612 | \n","
Kyrgyzstan | \n","5158 | \n","
Sierra Leone | \n","4937 | \n","
Mexico | \n","4793 | \n","
Tanzania | \n","4789 | \n","
Indonesia | \n","4523 | \n","
Ghana | \n","4152 | \n","
Zimbabwe | \n","3913 | \n","
Jordan | \n","3802 | \n","
Haiti | \n","3529 | \n","
Liberia | \n","3512 | \n","
Madagascar | \n","3356 | \n","
Mozambique | \n","3103 | \n","
The Democratic Republic of the Congo | \n","2940 | \n","
Timor-Leste | \n","2446 | \n","
Burkina Faso | \n","2402 | \n","
Georgia | \n","2232 | \n","
Yemen | \n","2146 | \n","
Egypt | \n","1600 | \n","
Myanmar (Burma) | \n","1559 | \n","
Cameroon | \n","1529 | \n","
Azerbaijan | \n","1498 | \n","
Lao People's Democratic Republic | \n","1483 | \n","
Costa Rica | \n","1421 | \n","
Albania | \n","1414 | \n","
Malawi | \n","1263 | \n","
XGBRegressor(base_score=None, booster=None, callbacks=None,\n"," colsample_bylevel=None, colsample_bynode=None,\n"," colsample_bytree=None, device=None, early_stopping_rounds=None,\n"," enable_categorical=False, eval_metric=None, feature_types=None,\n"," gamma=None, grow_policy=None, importance_type=None,\n"," interaction_constraints=None, learning_rate=None, max_bin=None,\n"," max_cat_threshold=None, max_cat_to_onehot=None,\n"," max_delta_step=None, max_depth=None, max_leaves=None,\n"," min_child_weight=None, missing=nan, monotone_constraints=None,\n"," multi_strategy=None, n_estimators=None, n_jobs=None,\n"," num_parallel_tree=None, random_state=42, ...)In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
XGBRegressor(base_score=None, booster=None, callbacks=None,\n"," colsample_bylevel=None, colsample_bynode=None,\n"," colsample_bytree=None, device=None, early_stopping_rounds=None,\n"," enable_categorical=False, eval_metric=None, feature_types=None,\n"," gamma=None, grow_policy=None, importance_type=None,\n"," interaction_constraints=None, learning_rate=None, max_bin=None,\n"," max_cat_threshold=None, max_cat_to_onehot=None,\n"," max_delta_step=None, max_depth=None, max_leaves=None,\n"," min_child_weight=None, missing=nan, monotone_constraints=None,\n"," multi_strategy=None, n_estimators=None, n_jobs=None,\n"," num_parallel_tree=None, random_state=42, ...)
LinearRegression()In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
LinearRegression()
XGBRegressor(base_score=None, booster=None, callbacks=None,\n"," colsample_bylevel=None, colsample_bynode=None,\n"," colsample_bytree=0.7, device=None, early_stopping_rounds=None,\n"," enable_categorical=False, eval_metric=None, feature_types=None,\n"," gamma=None, grow_policy=None, importance_type=None,\n"," interaction_constraints=None, learning_rate=0.01, max_bin=None,\n"," max_cat_threshold=None, max_cat_to_onehot=None,\n"," max_delta_step=None, max_depth=3, max_leaves=None,\n"," min_child_weight=None, missing=nan, monotone_constraints=None,\n"," multi_strategy=None, n_estimators=100, n_jobs=None,\n"," num_parallel_tree=None, random_state=42, ...)In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
XGBRegressor(base_score=None, booster=None, callbacks=None,\n"," colsample_bylevel=None, colsample_bynode=None,\n"," colsample_bytree=0.7, device=None, early_stopping_rounds=None,\n"," enable_categorical=False, eval_metric=None, feature_types=None,\n"," gamma=None, grow_policy=None, importance_type=None,\n"," interaction_constraints=None, learning_rate=0.01, max_bin=None,\n"," max_cat_threshold=None, max_cat_to_onehot=None,\n"," max_delta_step=None, max_depth=3, max_leaves=None,\n"," min_child_weight=None, missing=nan, monotone_constraints=None,\n"," multi_strategy=None, n_estimators=100, n_jobs=None,\n"," num_parallel_tree=None, random_state=42, ...)