Commit 88812fda authored by Jonathan Poalses's avatar Jonathan Poalses

Added GNB, KNeighbour, and SVC ML implementations

parent 5cd7726d
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
"cells": [ "cells": [
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 105, "execution_count": 124,
"metadata": { "metadata": {
"collapsed": true, "collapsed": true,
"ExecuteTime": { "ExecuteTime": {
"end_time": "2023-05-18T01:58:43.027132Z", "end_time": "2023-05-18T02:41:10.395299Z",
"start_time": "2023-05-18T01:58:43.019344Z" "start_time": "2023-05-18T02:41:10.386829Z"
} }
}, },
"outputs": [], "outputs": [],
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 106, "execution_count": 125,
"outputs": [], "outputs": [],
"source": [ "source": [
"data = vectorizer.fit_transform(edn.loads(open(\"sample_data.txt\").read()))\n", "data = vectorizer.fit_transform(edn.loads(open(\"sample_data.txt\").read()))\n",
...@@ -30,14 +30,14 @@ ...@@ -30,14 +30,14 @@
"metadata": { "metadata": {
"collapsed": false, "collapsed": false,
"ExecuteTime": { "ExecuteTime": {
"end_time": "2023-05-18T01:58:43.043055Z", "end_time": "2023-05-18T02:41:10.409258Z",
"start_time": "2023-05-18T01:58:43.026725Z" "start_time": "2023-05-18T02:41:10.397755Z"
} }
} }
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 107, "execution_count": 126,
"outputs": [], "outputs": [],
"source": [ "source": [
"X_train, X_test, y_train, y_test = train_test_split(data, target, test_size=0.2, random_state=42)" "X_train, X_test, y_train, y_test = train_test_split(data, target, test_size=0.2, random_state=42)"
...@@ -45,95 +45,14 @@ ...@@ -45,95 +45,14 @@
"metadata": { "metadata": {
"collapsed": false, "collapsed": false,
"ExecuteTime": { "ExecuteTime": {
"end_time": "2023-05-18T01:58:43.066023Z", "end_time": "2023-05-18T02:41:10.415818Z",
"start_time": "2023-05-18T01:58:43.054110Z" "start_time": "2023-05-18T02:41:10.412071Z"
} }
} }
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 108, "execution_count": 127,
"outputs": [],
"source": [
"from sklearn.naive_bayes import GaussianNB"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-05-18T01:58:43.066927Z",
"start_time": "2023-05-18T01:58:43.060309Z"
}
}
},
{
"cell_type": "code",
"execution_count": 109,
"outputs": [
{
"data": {
"text/plain": "GaussianNB()",
"text/html": "<style>#sk-container-id-14 {color: black;background-color: white;}#sk-container-id-14 pre{padding: 0;}#sk-container-id-14 div.sk-toggleable {background-color: white;}#sk-container-id-14 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-14 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-14 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-14 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-14 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-14 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-14 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-14 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-14 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-14 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-14 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-14 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-14 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-14 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-14 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-14 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-14 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-14 div.sk-item {position: relative;z-index: 1;}#sk-container-id-14 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-14 div.sk-item::before, #sk-container-id-14 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-14 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-14 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-14 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-14 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-14 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-14 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-14 div.sk-label-container {text-align: center;}#sk-container-id-14 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-14 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-14\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>GaussianNB()</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-14\" type=\"checkbox\" checked><label for=\"sk-estimator-id-14\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">GaussianNB</label><div class=\"sk-toggleable__content\"><pre>GaussianNB()</pre></div></div></div></div></div>"
},
"execution_count": 109,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gnb = GaussianNB()\n",
"gnb.fit((X_train).toarray(), y_train)"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-05-18T01:58:43.077601Z",
"start_time": "2023-05-18T01:58:43.067375Z"
}
}
},
{
"cell_type": "code",
"execution_count": 110,
"outputs": [],
"source": [
"predicted=gnb.predict((X_test).toarray())\n",
"expected = y_test"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-05-18T01:58:43.082487Z",
"start_time": "2023-05-18T01:58:43.078846Z"
}
}
},
{
"cell_type": "code",
"execution_count": 111,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"75.00%\n"
]
}
],
"source": [
"wrong=[ (p, e) for (p, e) in zip(predicted, expected) if p != e]\n",
"print(f'{(len(expected) - len(wrong)) / len(expected):.2%}')"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-05-18T01:58:43.093743Z",
"start_time": "2023-05-18T01:58:43.084280Z"
}
}
},
{
"cell_type": "code",
"execution_count": 112,
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
...@@ -144,13 +63,16 @@ ...@@ -144,13 +63,16 @@
} }
], ],
"source": [ "source": [
"from sklearn.naive_bayes import GaussianNB\n",
"gnb = GaussianNB()\n",
"gnb.fit((X_train).toarray(), y_train)\n",
"print(f'{gnb.score((X_test).toarray(), y_test): .2%}')" "print(f'{gnb.score((X_test).toarray(), y_test): .2%}')"
], ],
"metadata": { "metadata": {
"collapsed": false, "collapsed": false,
"ExecuteTime": { "ExecuteTime": {
"end_time": "2023-05-18T01:58:43.109002Z", "end_time": "2023-05-18T02:41:10.428856Z",
"start_time": "2023-05-18T01:58:43.087892Z" "start_time": "2023-05-18T02:41:10.417634Z"
} }
} }
} }
......
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
"cells": [ "cells": [
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 57, "execution_count": 76,
"metadata": { "metadata": {
"collapsed": true, "collapsed": true,
"ExecuteTime": { "ExecuteTime": {
"end_time": "2023-05-18T01:58:46.040817Z", "end_time": "2023-05-18T02:41:18.336164Z",
"start_time": "2023-05-18T01:58:46.036097Z" "start_time": "2023-05-18T02:41:18.331276Z"
} }
}, },
"outputs": [], "outputs": [],
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 58, "execution_count": 77,
"outputs": [], "outputs": [],
"source": [ "source": [
"data = vectorizer.fit_transform(edn.loads(open(\"sample_data.txt\").read()))\n", "data = vectorizer.fit_transform(edn.loads(open(\"sample_data.txt\").read()))\n",
...@@ -30,14 +30,14 @@ ...@@ -30,14 +30,14 @@
"metadata": { "metadata": {
"collapsed": false, "collapsed": false,
"ExecuteTime": { "ExecuteTime": {
"end_time": "2023-05-18T01:58:46.083314Z", "end_time": "2023-05-18T02:41:18.353544Z",
"start_time": "2023-05-18T01:58:46.042782Z" "start_time": "2023-05-18T02:41:18.336411Z"
} }
} }
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 59, "execution_count": 78,
"outputs": [], "outputs": [],
"source": [ "source": [
"X_train, X_test, y_train, y_test = train_test_split(data, target, test_size=0.2, random_state=42)" "X_train, X_test, y_train, y_test = train_test_split(data, target, test_size=0.2, random_state=42)"
...@@ -45,95 +45,14 @@ ...@@ -45,95 +45,14 @@
"metadata": { "metadata": {
"collapsed": false, "collapsed": false,
"ExecuteTime": { "ExecuteTime": {
"end_time": "2023-05-18T01:58:46.099054Z", "end_time": "2023-05-18T02:41:18.359671Z",
"start_time": "2023-05-18T01:58:46.093034Z" "start_time": "2023-05-18T02:41:18.356890Z"
} }
} }
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 60, "execution_count": 79,
"outputs": [],
"source": [
"from sklearn.neighbors import KNeighborsClassifier"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-05-18T01:58:46.103466Z",
"start_time": "2023-05-18T01:58:46.099846Z"
}
}
},
{
"cell_type": "code",
"execution_count": 61,
"outputs": [
{
"data": {
"text/plain": "KNeighborsClassifier()",
"text/html": "<style>#sk-container-id-8 {color: black;background-color: white;}#sk-container-id-8 pre{padding: 0;}#sk-container-id-8 div.sk-toggleable {background-color: white;}#sk-container-id-8 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-8 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-8 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-8 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-8 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-8 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-8 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-8 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-8 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-8 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-8 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-8 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-8 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-8 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-8 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-8 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-8 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-8 div.sk-item {position: relative;z-index: 1;}#sk-container-id-8 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-8 div.sk-item::before, #sk-container-id-8 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-8 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-8 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-8 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-8 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-8 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-8 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-8 div.sk-label-container {text-align: center;}#sk-container-id-8 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-8 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-8\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>KNeighborsClassifier()</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-8\" type=\"checkbox\" checked><label for=\"sk-estimator-id-8\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">KNeighborsClassifier</label><div class=\"sk-toggleable__content\"><pre>KNeighborsClassifier()</pre></div></div></div></div></div>"
},
"execution_count": 61,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"knc = KNeighborsClassifier()\n",
"knc.fit(X_train, y_train)"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-05-18T01:58:46.117344Z",
"start_time": "2023-05-18T01:58:46.110609Z"
}
}
},
{
"cell_type": "code",
"execution_count": 62,
"outputs": [],
"source": [
"predicted=knc.predict(X_test)\n",
"expected = y_test"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-05-18T01:58:46.122772Z",
"start_time": "2023-05-18T01:58:46.118837Z"
}
}
},
{
"cell_type": "code",
"execution_count": 63,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"65.00%\n"
]
}
],
"source": [
"wrong=[ (p, e) for (p, e) in zip(predicted, expected) if p != e]\n",
"print(f'{(len(expected) - len(wrong)) / len(expected):.2%}')"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-05-18T01:58:46.126935Z",
"start_time": "2023-05-18T01:58:46.124164Z"
}
}
},
{
"cell_type": "code",
"execution_count": 64,
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
...@@ -144,13 +63,16 @@ ...@@ -144,13 +63,16 @@
} }
], ],
"source": [ "source": [
"from sklearn.neighbors import KNeighborsClassifier\n",
"knc = KNeighborsClassifier()\n",
"knc.fit(X_train, y_train)\n",
"print(f'{knc.score(X_test, y_test): .2%}')" "print(f'{knc.score(X_test, y_test): .2%}')"
], ],
"metadata": { "metadata": {
"collapsed": false, "collapsed": false,
"ExecuteTime": { "ExecuteTime": {
"end_time": "2023-05-18T01:58:46.132578Z", "end_time": "2023-05-18T02:41:18.370524Z",
"start_time": "2023-05-18T01:58:46.128149Z" "start_time": "2023-05-18T02:41:18.362461Z"
} }
} }
} }
......
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
"cells": [ "cells": [
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 438, "execution_count": 461,
"metadata": { "metadata": {
"collapsed": true, "collapsed": true,
"ExecuteTime": { "ExecuteTime": {
"end_time": "2023-05-18T01:58:39.308492Z", "end_time": "2023-05-18T02:41:46.523940Z",
"start_time": "2023-05-18T01:58:39.302389Z" "start_time": "2023-05-18T02:41:46.517479Z"
} }
}, },
"outputs": [], "outputs": [],
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 439, "execution_count": 462,
"outputs": [], "outputs": [],
"source": [ "source": [
"data = vectorizer.fit_transform(edn.loads(open(\"sample_data.txt\").read()))\n", "data = vectorizer.fit_transform(edn.loads(open(\"sample_data.txt\").read()))\n",
...@@ -30,14 +30,14 @@ ...@@ -30,14 +30,14 @@
"metadata": { "metadata": {
"collapsed": false, "collapsed": false,
"ExecuteTime": { "ExecuteTime": {
"end_time": "2023-05-18T01:58:39.340125Z", "end_time": "2023-05-18T02:41:46.541875Z",
"start_time": "2023-05-18T01:58:39.312108Z" "start_time": "2023-05-18T02:41:46.524547Z"
} }
} }
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 440, "execution_count": 463,
"outputs": [], "outputs": [],
"source": [ "source": [
"X_train, X_test, y_train, y_test = train_test_split(data, target, test_size=0.2, random_state=42)" "X_train, X_test, y_train, y_test = train_test_split(data, target, test_size=0.2, random_state=42)"
...@@ -45,95 +45,14 @@ ...@@ -45,95 +45,14 @@
"metadata": { "metadata": {
"collapsed": false, "collapsed": false,
"ExecuteTime": { "ExecuteTime": {
"end_time": "2023-05-18T01:58:39.351322Z", "end_time": "2023-05-18T02:41:46.550473Z",
"start_time": "2023-05-18T01:58:39.341456Z" "start_time": "2023-05-18T02:41:46.544756Z"
} }
} }
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 441, "execution_count": 464,
"outputs": [],
"source": [
"from sklearn.svm import SVC"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-05-18T01:58:39.368348Z",
"start_time": "2023-05-18T01:58:39.355705Z"
}
}
},
{
"cell_type": "code",
"execution_count": 442,
"outputs": [
{
"data": {
"text/plain": "SVC()",
"text/html": "<style>#sk-container-id-46 {color: black;background-color: white;}#sk-container-id-46 pre{padding: 0;}#sk-container-id-46 div.sk-toggleable {background-color: white;}#sk-container-id-46 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-46 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-46 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-46 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-46 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-46 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-46 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-46 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-46 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-46 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-46 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-46 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-46 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-46 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-46 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-46 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-46 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-46 div.sk-item {position: relative;z-index: 1;}#sk-container-id-46 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-46 div.sk-item::before, #sk-container-id-46 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-46 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-46 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-46 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-46 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-46 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-46 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-46 div.sk-label-container {text-align: center;}#sk-container-id-46 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-46 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-46\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>SVC()</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-46\" type=\"checkbox\" checked><label for=\"sk-estimator-id-46\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">SVC</label><div class=\"sk-toggleable__content\"><pre>SVC()</pre></div></div></div></div></div>"
},
"execution_count": 442,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"svc = SVC(gamma='scale')\n",
"svc.fit(X_train, y_train)"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-05-18T01:58:39.384555Z",
"start_time": "2023-05-18T01:58:39.371641Z"
}
}
},
{
"cell_type": "code",
"execution_count": 443,
"outputs": [],
"source": [
"predicted=svc.predict(X_test)\n",
"expected = y_test"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-05-18T01:58:39.393847Z",
"start_time": "2023-05-18T01:58:39.386304Z"
}
}
},
{
"cell_type": "code",
"execution_count": 444,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"55.00%\n"
]
}
],
"source": [
"wrong=[ (p, e) for (p, e) in zip(predicted, expected) if p != e]\n",
"print(f'{(len(expected) - len(wrong)) / len(expected):.2%}')"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-05-18T01:58:39.405299Z",
"start_time": "2023-05-18T01:58:39.395221Z"
}
}
},
{
"cell_type": "code",
"execution_count": 445,
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
...@@ -144,13 +63,16 @@ ...@@ -144,13 +63,16 @@
} }
], ],
"source": [ "source": [
"from sklearn.svm import SVC\n",
"svc = SVC(gamma='scale')\n",
"svc.fit(X_train, y_train)\n",
"print(f'{svc.score(X_test, y_test): .2%}')" "print(f'{svc.score(X_test, y_test): .2%}')"
], ],
"metadata": { "metadata": {
"collapsed": false, "collapsed": false,
"ExecuteTime": { "ExecuteTime": {
"end_time": "2023-05-18T01:58:39.413605Z", "end_time": "2023-05-18T02:41:46.559888Z",
"start_time": "2023-05-18T01:58:39.407510Z" "start_time": "2023-05-18T02:41:46.551307Z"
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment