8000 Added the ML Projects · d-coder111/SpectrumOfPython@14efb70 · GitHub
[go: up one dir, main page]

Skip to content

Commit 14efb70

Browse files
committed
Added the ML Projects
1 parent 779bdff commit 14efb70

File tree

14 files changed

+1111242
-0
lines changed

14 files changed

+1111242
-0
lines changed

ML Projects/Customer Purchase Prediction Model Using Logistic Regression/large_customer_data.csv

Lines changed: 1000001 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
"nbformat": 4,
3+
"nbformat_minor": 0,
4+
"metadata": {
5+
"colab": {
6+
"provenance": []
7+
},
8+
"kernelspec": {
9+
"name": "python3",
10+
"display_name": "Python 3"
11+
},
12+
"language_info": {
13+
"name": "python"
14+
}
15+
},
16+
"cells": [
17+
{
18+
"cell_type": "code",
19+
"execution_count": 2,
20+
"metadata": {
21+
"colab": {
22+
"base_uri": "https://localhost:8080/"
23+
},
24+
"id": "K6ZifZM98GkT",
25+
"outputId": "efd22c1c-6ba0-4d1e-94a6-a666f260623b"
26+
},
27+
"outputs": [
28+
{
29+
"output_type": "stream",
30+
"name": "stdout",
31+
"text": [
32+
"Predicted values: [0 1 0 ... 1 1 1]\n",
33+
"Actual values: [0 1 0 ... 1 1 1]\n",
34+
"Accuracy of the model: 87.39%\n",
35+
"Confusion Matrix:\n",
36+
"[[ 39912 19954]\n",
37+
" [ 5261 134873]]\n"
38+
]
39+
}
40+
],
41+
"source": [
42+
"import numpy as np\n",
43+
"import pandas as pd\n",
44+
"from sklearn.model_selection import train_test_split\n",
45+
"from sklearn.preprocessing import StandardScaler\n",
46+
"from sklearn.linear_model import LogisticRegression\n",
47+
"from sklearn.metrics import accuracy_score, confusion_matrix\n",
48+
"\n",
49+
"df = pd.read_csv('large_customer_data.csv')\n",
50+
"\n",
51+
"X = df[['Age', 'EstimatedSalary']]\n",
52+
"y = df['Purchased']\n",
53+
"\n",
54+
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
55+
"\n",
56+
"scaler = StandardScaler()\n",
57+
"X_train_scaled = scaler.fit_transform(X_train)\n",
58+
"X_test_scaled = scaler.transform(X_test)\n",
59+
"\n",
60+
"model = LogisticRegression()\n",
61+
"model.fit(X_train_scaled, y_train)\n",
62+
"\n",
63+
"y_pred = model.predict(X_test_scaled)\n",
64+
"\n",
65+
"accuracy = accuracy_score(y_test, y_pred)\n",
66+
"conf_matrix = confusion_matrix(y_test, y_pred)\n",
67+
"\n",
68+
"print(f\"Predicted values: {y_pred}\")\n",
69+
"print(f\"Actual values: {y_test.values}\")\n",
70+
"print(f\"Accuracy of the model: {accuracy * 100:.2f}%\")\n",
71+
"print(f\"Confusion Matrix:\\n{conf_matrix}\")\n"
72+
]
73+
},
74+
{
75+
"cell_type": "code",
76+
"source": [],
77+
"metadata": {
78+
"id": "BTu91qrS8K9O"
79+
},
80+
"execution_count": null,
81+
"outputs": []
82+
}
83+
]
84+
}

0 commit comments

Comments
 (0)
0