Skip to content
This repository was archived by the owner on May 25, 2022. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions projects/LOAN/Project_2 LOAN.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"'''\n",
"LOAN DATASET\n",
"'''\n",
"\n",
"# required libraries\n",
"import pandas as pd\n",
"from sklearn.linear_model import LogisticRegression\n",
"from sklearn.model_selection import train_test_split\n",
"from sklearn.preprocessing import LabelEncoder\n",
"from sklearn.metrics import accuracy_score\n",
"\n",
"\n",
"# read the dataset\n",
"data = pd.read_csv('train_ctrUa4K.csv')\n",
"print(data.head())\n",
"\n",
"print('\\n\\nColumn Names\\n\\n')\n",
"print(data.columns)\n",
"\n",
"#label encode the target variable\n",
"encode = LabelEncoder()\n",
"data.Loan_Status = encode.fit_transform(data.Loan_Status)\n",
"\n",
"# drop the null values\n",
"data.dropna(how='any',inplace=True)\n",
"\n",
"\n",
"# train-test-split \n",
"train , test = train_test_split(data,test_size=0.2,random_state=0)\n",
"\n",
"\n",
"\n",
"# seperate the target and independent variable\n",
"train_x = train.drop(columns=['Loan_ID','Loan_Status'],axis=1)\n",
"train_y = train['Loan_Status']\n",
"\n",
"test_x = test.drop(columns=['Loan_ID','Loan_Status'],axis=1)\n",
"test_y = test['Loan_Status']\n",
"\n",
"# encode the data\n",
"train_x = pd.get_dummies(train_x)\n",
"test_x = pd.get_dummies(test_x)\n",
"\n",
"print('shape of training data : ',train_x.shape)\n",
"print('shape of testing data : ',test_x.shape)\n",
"\n",
"# create the object of the model\n",
"model = LogisticRegression()\n",
"\n",
"model.fit(train_x,train_y)\n",
"\n",
"predict = model.predict(test_x)\n",
"\n",
"print('Predicted Values on Test Data',predict)\n",
"\n",
"print('\\n\\nAccuracy Score on test data : \\n\\n')\n",
"print(accuracy_score(test_y,predict))\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}