{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "exposed-browse", "metadata": {}, "outputs": [], "source": [ "import pandas as pd \n", "import numpy as np\n", "import matplotlib.pyplot as plt \n", "import seaborn as sns\n", "from sklearn.model_selection import train_test_split\n", "from sklearn.metrics import confusion_matrix, classification_report\n", "from sklearn.preprocessing import StandardScaler\n", "from sklearn.svm import SVC\n", "from sklearn.tree import DecisionTreeClassifier\n", "from sklearn.neighbors import KNeighborsClassifier\n", "import xgboost as xgb\n", "import torch\n", "\n", "def eval(model,x_test,y_test, nn = None):\n", " if nn == None:\n", " print(classification_report(y_test,model.predict(x_test)))\n", " else:\n", " y_pred = model(torch.tensor(x_test.astype(np.float32)))\n", " y_pred = y_pred.cpu().detach().numpy() \n", " y_pred = (y_pred > 0.5)\n", " y_pred = np.asarray(y_pred, dtype=np.int32)\n", " print(classification_report(y_test,y_pred))\n", " " ] }, { "cell_type": "code", "execution_count": 2, "id": "unlimited-modern", "metadata": {}, "outputs": [], "source": [ "data = pd.read_csv('water_potability.csv')" ] }, { "cell_type": "code", "execution_count": 3, "id": "simplified-ranch", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | ph | \n", "Hardness | \n", "Solids | \n", "Chloramines | \n", "Sulfate | \n", "Conductivity | \n", "Organic_carbon | \n", "Trihalomethanes | \n", "Turbidity | \n", "Potability | \n", "
---|---|---|---|---|---|---|---|---|---|---|
count | \n", "2785.000000 | \n", "3276.000000 | \n", "3276.000000 | \n", "3276.000000 | \n", "2495.000000 | \n", "3276.000000 | \n", "3276.000000 | \n", "3114.000000 | \n", "3276.000000 | \n", "3276.000000 | \n", "
mean | \n", "7.080795 | \n", "196.369496 | \n", "22014.092526 | \n", "7.122277 | \n", "333.775777 | \n", "426.205111 | \n", "14.284970 | \n", "66.396293 | \n", "3.966786 | \n", "0.390110 | \n", "
std | \n", "1.594320 | \n", "32.879761 | \n", "8768.570828 | \n", "1.583085 | \n", "41.416840 | \n", "80.824064 | \n", "3.308162 | \n", "16.175008 | \n", "0.780382 | \n", "0.487849 | \n", "
min | \n", "0.000000 | \n", "47.432000 | \n", "320.942611 | \n", "0.352000 | \n", "129.000000 | \n", "181.483754 | \n", "2.200000 | \n", "0.738000 | \n", "1.450000 | \n", "0.000000 | \n", "
25% | \n", "6.093092 | \n", "176.850538 | \n", "15666.690297 | \n", "6.127421 | \n", "307.699498 | \n", "365.734414 | \n", "12.065801 | \n", "55.844536 | \n", "3.439711 | \n", "0.000000 | \n", "
50% | \n", "7.036752 | \n", "196.967627 | \n", "20927.833607 | \n", "7.130299 | \n", "333.073546 | \n", "421.884968 | \n", "14.218338 | \n", "66.622485 | \n", "3.955028 | \n", "0.000000 | \n", "
75% | \n", "8.062066 | \n", "216.667456 | \n", "27332.762127 | \n", "8.114887 | \n", "359.950170 | \n", "481.792304 | \n", "16.557652 | \n", "77.337473 | \n", "4.500320 | \n", "1.000000 | \n", "
max | \n", "14.000000 | \n", "323.124000 | \n", "61227.196008 | \n", "13.127000 | \n", "481.030642 | \n", "753.342620 | \n", "28.300000 | \n", "124.000000 | \n", "6.739000 | \n", "1.000000 | \n", "