Skip to content

Commit

Permalink
Merge pull request #207 from vertica/bugfix_calssification_lesson
Browse files Browse the repository at this point in the history
Bugfix calssification lesson
  • Loading branch information
mail4umar committed Jul 24, 2023
2 parents 6170ebd + 17aa246 commit 4a46b8d
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1356,63 +1356,16 @@
"metadata": {},
"outputs": [],
"source": [
"from verticapy.machine_learning.vertica.linear_model import LogisticRegression\n",
"model = LogisticRegression(\"public.LR_default\")"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "59bd58f8-976d-4c57-abba-b384f0dd3f13",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\n",
"\n",
"=======\n",
"details\n",
"=======\n",
" predictor |coefficient|std_err | z_value |p_value \n",
"--------------+-----------+--------+---------+--------\n",
" Intercept | -11.15139 | 0.57746|-19.31113| 0.00000\n",
"credit_balance| 0.00587 | 0.00027|21.60061 | 0.00000\n",
" income | 0.00001 | 0.00001| 0.63721 | 0.52399\n",
" student | -0.60562 | 0.27726|-2.18431 | 0.02894\n",
"\n",
"\n",
"==============\n",
"regularization\n",
"==============\n",
"type| lambda \n",
"----+--------\n",
"none| 1.00000\n",
"\n",
"\n",
"===========\n",
"call_string\n",
"===========\n",
"logistic_reg('public.LR_default', '\"public\".\"_verticapy_tmp_view_dbadmin_6064_718428356_\"', '\"default\"', '\"credit_balance\", \"income\", \"student\"'\n",
"USING PARAMETERS optimizer='newton', epsilon=1e-06, max_iterations=100, regularization='none', lambda=1, alpha=0.5, fit_intercept=true)\n",
"\n",
"===============\n",
"Additional Info\n",
"===============\n",
" Name |Value\n",
"------------------+-----\n",
" iteration_count | 8 \n",
"rejected_row_count| 0 \n",
"accepted_row_count|7618 "
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"model.fit(data, [\"credit_balance\", \"income\",\"student\"], \"default\")"
"file = open(\"Figures/result.PNG\", \"rb\")\n",
"image = file.read()\n",
"\n",
"image_0= widgets.Image(\n",
" value=image,\n",
" format='png',\n",
" width='500px'\n",
" )\n",
"\n",
"display(image_0)"
]
},
{
Expand All @@ -1433,6 +1386,7 @@
"\n",
"```python\n",
"model.fit(data, [\"credit_balance\", \"income\",\"student\"], \"default\")\n",
"model.classification_report(metrics=[\"accuracy\",\"auc\",\"precision\",\"specificity\"])\n",
"```"
]
},
Expand All @@ -1454,7 +1408,17 @@
}
],
"source": [
"model.classification_report(metrics=[\"accuracy\",\"auc\",\"precision\",\"specificity\"])"
"\n",
"file = open(\"Figures/report1.PNG\", \"rb\")\n",
"image = file.read()\n",
"\n",
"image_0= widgets.Image(\n",
" value=image,\n",
" format='png',\n",
" width='300px'\n",
" )\n",
"\n",
"display(image_0)"
]
},
{
Expand Down Expand Up @@ -1601,80 +1565,62 @@
"Let us train again to see if we improved."
]
},
{
"cell_type": "markdown",
"id": "d73ace51",
"metadata": {},
"source": [
"```python\n",
"model.fit(balanced_data, [\"credit_balance\", \"income\",\"student\"], \"default\")\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "64efeb90-8470-445d-ba57-b7788ef47957",
"execution_count": null,
"id": "7043aad7",
"metadata": {},
"outputs": [],
"source": [
"file = open(\"Figures/result2.PNG\", \"rb\")\n",
"image = file.read()\n",
"\n",
"image_0= widgets.Image(\n",
" value=image,\n",
" format='png',\n",
" width='500px'\n",
" )\n",
"\n",
"display(image_0)"
]
},
{
"cell_type": "markdown",
"id": "dfd19aab",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\n",
"\n",
"=======\n",
"details\n",
"=======\n",
" predictor |coefficient|std_err | z_value |p_value \n",
"--------------+-----------+--------+---------+--------\n",
" Intercept | -8.87974 | 0.73503|-12.08072| 0.00000\n",
"credit_balance| 0.00589 | 0.00038|15.51593 | 0.00000\n",
" income | -0.00000 | 0.00001|-0.10420 | 0.91701\n",
" student | -0.90451 | 0.37083|-2.43915 | 0.01472\n",
"\n",
"\n",
"==============\n",
"regularization\n",
"==============\n",
"type| lambda \n",
"----+--------\n",
"none| 1.00000\n",
"\n",
"\n",
"===========\n",
"call_string\n",
"===========\n",
"logistic_reg('public.LR_default', '\"public\".\"_verticapy_tmp_view_dbadmin_6064_7892778534_\"', '\"default\"', '\"credit_balance\", \"income\", \"student\"'\n",
"USING PARAMETERS optimizer='newton', epsilon=1e-06, max_iterations=100, regularization='none', lambda=1, alpha=0.5, fit_intercept=true)\n",
"\n",
"===============\n",
"Additional Info\n",
"===============\n",
" Name |Value\n",
"------------------+-----\n",
" iteration_count | 7 \n",
"rejected_row_count| 0 \n",
"accepted_row_count|1281 "
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"model.fit(balanced_data, [\"credit_balance\", \"income\",\"student\"], \"default\")"
"```python\n",
"model.classification_report(metrics=[\"accuracy\",\"auc\",\"precision\",\"specificity\"])\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "82512aca-6a0e-4a0a-80f9-fda5d33f205b",
"execution_count": null,
"id": "be585235",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Accuracy: 0.9039812646370023\n",
"AUC: 0.951080411585369\n",
"Precision: 0.7854077253218884\n",
"Specificity: 0.9512195121951219\n"
]
}
],
"outputs": [],
"source": [
"model.classification_report(metrics=[\"accuracy\",\"auc\",\"precision\",\"specificity\"])"
"file = open(\"Figures/report2.PNG\", \"rb\")\n",
"image = file.read()\n",
"\n",
"image_0= widgets.Image(\n",
" value=image,\n",
" format='png',\n",
" width='300px'\n",
" )\n",
"\n",
"display(image_0)"
]
},
{
Expand Down Expand Up @@ -1780,7 +1726,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.9.12 ('web')",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4a46b8d

Please sign in to comment.