Skip to content
This repository was archived by the owner on May 25, 2022. It is now read-only.

Commit 884f143

Browse files
committed
Added a LOAN prediction project using python with jupyter based on Data Analysis
1 parent 8688fd6 commit 884f143

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

projects/LOAN/Project_2 LOAN.ipynb

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"'''\n",
10+
"LOAN DATASET\n",
11+
"'''\n",
12+
"\n",
13+
"# required libraries\n",
14+
"import pandas as pd\n",
15+
"from sklearn.linear_model import LogisticRegression\n",
16+
"from sklearn.model_selection import train_test_split\n",
17+
"from sklearn.preprocessing import LabelEncoder\n",
18+
"from sklearn.metrics import accuracy_score\n",
19+
"\n",
20+
"\n",
21+
"# read the dataset\n",
22+
"data = pd.read_csv('train_ctrUa4K.csv')\n",
23+
"print(data.head())\n",
24+
"\n",
25+
"print('\\n\\nColumn Names\\n\\n')\n",
26+
"print(data.columns)\n",
27+
"\n",
28+
"#label encode the target variable\n",
29+
"encode = LabelEncoder()\n",
30+
"data.Loan_Status = encode.fit_transform(data.Loan_Status)\n",
31+
"\n",
32+
"# drop the null values\n",
33+
"data.dropna(how='any',inplace=True)\n",
34+
"\n",
35+
"\n",
36+
"# train-test-split \n",
37+
"train , test = train_test_split(data,test_size=0.2,random_state=0)\n",
38+
"\n",
39+
"\n",
40+
"\n",
41+
"# seperate the target and independent variable\n",
42+
"train_x = train.drop(columns=['Loan_ID','Loan_Status'],axis=1)\n",
43+
"train_y = train['Loan_Status']\n",
44+
"\n",
45+
"test_x = test.drop(columns=['Loan_ID','Loan_Status'],axis=1)\n",
46+
"test_y = test['Loan_Status']\n",
47+
"\n",
48+
"# encode the data\n",
49+
"train_x = pd.get_dummies(train_x)\n",
50+
"test_x = pd.get_dummies(test_x)\n",
51+
"\n",
52+
"print('shape of training data : ',train_x.shape)\n",
53+
"print('shape of testing data : ',test_x.shape)\n",
54+
"\n",
55+
"# create the object of the model\n",
56+
"model = LogisticRegression()\n",
57+
"\n",
58+
"model.fit(train_x,train_y)\n",
59+
"\n",
60+
"predict = model.predict(test_x)\n",
61+
"\n",
62+
"print('Predicted Values on Test Data',predict)\n",
63+
"\n",
64+
"print('\\n\\nAccuracy Score on test data : \\n\\n')\n",
65+
"print(accuracy_score(test_y,predict))\n"
66+
]
67+
}
68+
],
69+
"metadata": {
70+
"kernelspec": {
71+
"display_name": "Python 3",
72+
"language": "python",
73+
"name": "python3"
74+
},
75+
"language_info": {
76+
"codemirror_mode": {
77+
"name": "ipython",
78+
"version": 3
79+
},
80+
"file_extension": ".py",
81+
"mimetype": "text/x-python",
82+
"name": "python",
83+
"nbconvert_exporter": "python",
84+
"pygments_lexer": "ipython3",
85+
"version": "3.8.3"
86+
}
87+
},
88+
"nbformat": 4,
89+
"nbformat_minor": 4
90+
}

0 commit comments

Comments
 (0)