Add files via upload

This commit is contained in:
Aditya
2025-10-30 23:08:07 +05:30
committed by GitHub
commit d0bbee40e2
7 changed files with 1757 additions and 0 deletions
+1252
View File
File diff suppressed because one or more lines are too long
+121
View File
@@ -0,0 +1,121 @@
{
"metadata": {
"kernelspec": {
"name": "python",
"display_name": "Python (Pyodide)",
"language": "python"
},
"language_info": {
"codemirror_mode": {
"name": "python",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8"
}
},
"nbformat_minor": 5,
"nbformat": 4,
"cells": [
{
"id": "1787aa40-6173-48cb-ac24-169a13a92b25",
"cell_type": "code",
"source": "import pandas as pd\nimport numpy as np\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.neighbors import KNeighborsClassifier\nfrom sklearn.svm import SVC\nfrom sklearn.metrics import accuracy_score, confusion_matrix, classification_report",
"metadata": {
"trusted": true
},
"outputs": [],
"execution_count": 1
},
{
"id": "e529d131-cb7a-4408-8624-96b481da9f94",
"cell_type": "code",
"source": "data = pd.read_csv(\"emails.csv\")\nprint(data.head())",
"metadata": {
"trusted": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": " Email No. the to ect and for of a you hou ... connevey jay \\\n0 Email 1 0 0 1 0 0 0 2 0 0 ... 0 0 \n1 Email 2 8 13 24 6 6 2 102 1 27 ... 0 0 \n2 Email 3 0 0 1 0 0 0 8 0 0 ... 0 0 \n3 Email 4 0 5 22 0 5 1 51 2 10 ... 0 0 \n4 Email 5 7 6 17 1 5 2 57 0 9 ... 0 0 \n\n valued lay infrastructure military allowing ff dry Prediction \n0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 1 0 0 \n2 0 0 0 0 0 0 0 0 \n3 0 0 0 0 0 0 0 0 \n4 0 0 0 0 0 1 0 0 \n\n[5 rows x 3002 columns]\n"
}
],
"execution_count": 2
},
{
"id": "adcce56e-4742-4a1a-8ed6-82df3e5ad9c4",
"cell_type": "code",
"source": "X = data.drop(columns=['Email No.', 'Prediction'], errors='ignore') # features\ny = data['Prediction'] ",
"metadata": {
"trusted": true
},
"outputs": [],
"execution_count": null
},
{
"id": "963f4ccd-9790-4d1f-8458-995bdbfc84eb",
"cell_type": "code",
"source": "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=42)",
"metadata": {
"trusted": true
},
"outputs": [],
"execution_count": null
},
{
"id": "481d8d23-ce4d-4419-a820-779ad333be2a",
"cell_type": "code",
"source": "scaler = StandardScaler()\nX_train = scaler.fit_transform(X_train)\nX_test = scaler.transform(X_test)",
"metadata": {
"trusted": true
},
"outputs": [],
"execution_count": null
},
{
"id": "255b9746-202d-425b-9353-41d7bb18d99c",
"cell_type": "code",
"source": "knn = KNeighborsClassifier(n_neighbors=5)\nknn.fit(X_train, y_train)\ny_pred_knn = knn.predict(X_test)",
"metadata": {
"trusted": true
},
"outputs": [],
"execution_count": null
},
{
"id": "0c5e2c44-afc4-43d8-bdd7-e0a136d54413",
"cell_type": "code",
"source": "svm = SVC(kernel='linear', C=1)\nsvm.fit(X_train, y_train)\ny_pred_svm = svm.predict(X_test)",
"metadata": {
"trusted": true
},
"outputs": [],
"execution_count": null
},
{
"id": "77909086-350b-4442-97d6-e7bbef15648f",
"cell_type": "code",
"source": "print(\"===== KNN Model Evaluation =====\")\nprint(\"Accuracy:\", accuracy_score(y_test, y_pred_knn))\nprint(confusion_matrix(y_test, y_pred_knn))\nprint(classification_report(y_test, y_pred_knn))",
"metadata": {
"trusted": true
},
"outputs": [],
"execution_count": null
},
{
"id": "72a0433c-8085-4ea4-aa29-28ed856ab086",
"cell_type": "code",
"source": "print(\"\\n===== SVM Model Evaluation =====\")\nprint(\"Accuracy:\", accuracy_score(y_test, y_pred_svm))\nprint(confusion_matrix(y_test, y_pred_svm))\nprint(classification_report(y_test, y_pred_svm))",
"metadata": {
"trusted": true
},
"outputs": [],
"execution_count": null
}
]
}
File diff suppressed because one or more lines are too long
+95
View File
@@ -0,0 +1,95 @@
{
"metadata": {
"kernelspec": {
"name": "python",
"display_name": "Python (Pyodide)",
"language": "python"
},
"language_info": {
"codemirror_mode": {
"name": "python",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8"
}
},
"nbformat_minor": 5,
"nbformat": 4,
"cells": [
{
"id": "d4cec5b7-5725-44d3-bfb7-04278fdf9bb4",
"cell_type": "code",
"source": "import pandas as pd\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import StandardScaler, LabelEncoder\nfrom sklearn.neural_network import MLPClassifier\nfrom sklearn.metrics import accuracy_score, confusion_matrix",
"metadata": {
"trusted": true
},
"outputs": [],
"execution_count": 2
},
{
"id": "0e3d0d27-300b-4152-96e0-70ff1fbab83a",
"cell_type": "code",
"source": "data = pd.read_csv(\"Churn_Modelling.csv\")",
"metadata": {
"trusted": true
},
"outputs": [],
"execution_count": 3
},
{
"id": "06fd9a81-ed4d-4796-bc38-e0c68fe1dc3e",
"cell_type": "code",
"source": "X = data.iloc[:, 3:13] # Features from CreditScore to EstimatedSalary\ny = data.iloc[:, 13] ",
"metadata": {
"trusted": true
},
"outputs": [],
"execution_count": 4
},
{
"id": "90c9c5aa-0b8a-424b-a625-ff4fc2d73380",
"cell_type": "code",
"source": "le = LabelEncoder()\nX[\"Gender\"] = le.fit_transform(X[\"Gender\"])\nX = pd.get_dummies(X, columns=[\"Geography\"], drop_first=True)",
"metadata": {
"trusted": true
},
"outputs": [],
"execution_count": 5
},
{
"id": "4b0ecfe6-7245-4866-a842-e422c5658928",
"cell_type": "code",
"source": "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)",
"metadata": {
"trusted": true
},
"outputs": [],
"execution_count": 6
},
{
"id": "55cd9306-83f0-4ea6-8399-278444f3e839",
"cell_type": "code",
"source": "scaler = StandardScaler()\nX_train = scaler.fit_transform(X_train)\nX_test = scaler.transform(X_test)",
"metadata": {
"trusted": true
},
"outputs": [],
"execution_count": 7
},
{
"id": "60cdf8fb-c656-4a24-a120-de0c4c9abf94",
"cell_type": "code",
"source": "",
"metadata": {
"trusted": true
},
"outputs": [],
"execution_count": null
}
]
}
+19
View File
@@ -0,0 +1,19 @@
def f(x):
return (x + 3)**2
def df(x):
return 2 * (x + 3)
# Step 2: Initialize parameters
x = 2 # starting point
learning_rate = 0.1 # step size
epochs = 30 # number of iterations
# Step 3: Gradient Descent loop
for i in range(epochs):
grad = df(x) # compute gradient
x = x - learning_rate * grad # update x
print(f"Iteration {i+1}: x = {x:.4f}, f(x) = {f(x):.4f}")
print("\nLocal minima occurs at x =", round(x, 4))
print("Minimum value of function =", round(f(x), 4))
File diff suppressed because one or more lines are too long
+8
View File
@@ -0,0 +1,8 @@
{
"metadata": {
"orig_nbformat": 4
},
"nbformat_minor": 5,
"nbformat": 4,
"cells": []
}