Skip to content

Commit

Permalink
Added necessary comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sanskritiagr authored May 23, 2024
1 parent a6811e5 commit b7922a2
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion Loan-Prediction-main/Loan-Prediction-main/LoanPreds.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,14 @@
"df.Gender.value_counts(dropna=False)"
]
},
{
"cell_type": "markdown",
"id": "d0dec656",
"metadata": {},
"source": [
"# Data Visualization"
]
},
{
"cell_type": "code",
"execution_count": 9,
Expand Down Expand Up @@ -1073,6 +1081,14 @@
"sns.boxplot(x=\"Loan_Status\", y=\"LoanAmount\", data=df, palette=\"YlOrBr\");\n"
]
},
{
"cell_type": "markdown",
"id": "2e1578ff",
"metadata": {},
"source": [
"# Data Cleaning"
]
},
{
"cell_type": "code",
"execution_count": 27,
Expand Down Expand Up @@ -2158,6 +2174,14 @@
"sns.histplot(data=df, x=\"LoanAmount\", kde=True, ax=axs[1, 0], color='orange');"
]
},
{
"cell_type": "markdown",
"id": "d002f143",
"metadata": {},
"source": [
"# Training"
]
},
{
"cell_type": "code",
"execution_count": 39,
Expand Down Expand Up @@ -2186,6 +2210,7 @@
"metadata": {},
"outputs": [],
"source": [
"#Normalize the data\n",
"X = MinMaxScaler().fit_transform(X)"
]
},
Expand All @@ -2196,6 +2221,7 @@
"metadata": {},
"outputs": [],
"source": [
"#Splitting the data\n",
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.1, random_state = 48)"
]
},
Expand Down Expand Up @@ -2225,6 +2251,7 @@
}
],
"source": [
"#Linear Regression\n",
"LRclassifier =LogisticRegression()\n",
"LRclassifier.fit(X_train, y_train)\n",
"\n",
Expand Down Expand Up @@ -2263,6 +2290,7 @@
}
],
"source": [
"#K Nearest Neighbour\n",
"scoreListknn = []\n",
"for i in range(1,21):\n",
" KNclassifier = KNeighborsClassifier(n_neighbors = i)\n",
Expand Down Expand Up @@ -2312,6 +2340,7 @@
}
],
"source": [
"#Support Vector Machine\n",
"SVCclassifier = SVC(kernel='rbf', max_iter=500)\n",
"SVCclassifier.fit(X_train, y_train)\n",
"\n",
Expand Down Expand Up @@ -2350,6 +2379,7 @@
}
],
"source": [
"#Decision Tree\n",
"scoreListDT = []\n",
"for i in range(2,21):\n",
" DTclassifier = DecisionTreeClassifier(max_leaf_nodes=i)\n",
Expand Down Expand Up @@ -2390,6 +2420,7 @@
}
],
"source": [
"#Random Forest \n",
"scoreListRF = []\n",
"for i in range(2,25):\n",
" RFclassifier = RandomForestClassifier(n_estimators = 1000, random_state = 1, max_leaf_nodes=i)\n",
Expand All @@ -2412,6 +2443,7 @@
"metadata": {},
"outputs": [],
"source": [
"#For Grid Search\n",
"paramsGB={'n_estimators':[100,200,300,400,500],\n",
" 'max_depth':[1,2,3,4,5],\n",
" 'subsample':[0.5,1],\n",
Expand Down Expand Up @@ -2512,6 +2544,7 @@
}
],
"source": [
"#Gradient Boosting\n",
"GBclassifier = GradientBoostingClassifier(subsample=0.5, n_estimators=400, max_depth=4, max_leaf_nodes=10)\n",
"GBclassifier.fit(X_train, y_train)\n",
"\n",
Expand All @@ -2532,6 +2565,7 @@
"metadata": {},
"outputs": [],
"source": [
"#Save all the models for deployment\n",
"import pickle\n",
"pickle.dump(LRclassifier, open('model.pkl','wb'))\n",
"pickle.dump(KNclassifier, open('model2.pkl','wb'))\n",
Expand All @@ -2558,7 +2592,7 @@
},
{
"cell_type": "code",
"execution_count": 79,
"execution_count": null,
"id": "9a7dc512-cb24-4faa-9e59-04fcbc74554e",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -2622,6 +2656,7 @@
}
],
"source": [
"#Ensemblong the models\n",
"from sklearn.ensemble import VotingClassifier\n",
"final_model = VotingClassifier(\n",
" estimators=[('lr', model1), ('knn', model2), ('svc', model3),('dt', model4),('rf', model5),('gb', model6)], voting='hard')\n",
Expand Down Expand Up @@ -2665,6 +2700,7 @@
}
],
"source": [
"#FInal accuracies\n",
"print(classification_report(y_test, y_pred))\n",
"print(confusion_matrix(y_test, y_pred))\n",
"\n",
Expand Down

0 comments on commit b7922a2

Please sign in to comment.