Commit d3ae4489 authored by Jonathan Poalses's avatar Jonathan Poalses

Added GNB, KNeighbour, and SVC ML implementations

parent 316c8c2b
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
This diff is collapsed.
{
"cells": [
{
"cell_type": "code",
"execution_count": 265,
"metadata": {
"collapsed": true,
"ExecuteTime": {
"end_time": "2023-05-18T01:49:55.264368Z",
"start_time": "2023-05-18T01:49:55.259004Z"
}
},
"outputs": [],
"source": [
"import edn_format as edn\n",
"from sklearn.model_selection import train_test_split\n",
"from sklearn.feature_extraction.text import CountVectorizer\n",
"vectorizer = CountVectorizer()\n",
"analyze = vectorizer.build_analyzer()"
]
},
{
"cell_type": "code",
"execution_count": 266,
"outputs": [],
"source": [
"data = vectorizer.fit_transform(edn.loads(open(\"sample_data.txt\").read()))\n",
"target = edn.loads(open(\"sample_expected.txt\").read())"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-05-18T01:49:55.286323Z",
"start_time": "2023-05-18T01:49:55.267563Z"
}
}
},
{
"cell_type": "code",
"execution_count": 267,
"outputs": [],
"source": [
"X_train, X_test, y_train, y_test = train_test_split(data, target, test_size=0.2, random_state=1999)"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-05-18T01:49:55.292277Z",
"start_time": "2023-05-18T01:49:55.288051Z"
}
}
},
{
"cell_type": "code",
"execution_count": 268,
"outputs": [],
"source": [
"from sklearn.naive_bayes import GaussianNB"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-05-18T01:49:55.298594Z",
"start_time": "2023-05-18T01:49:55.295927Z"
}
}
},
{
"cell_type": "code",
"execution_count": 269,
"outputs": [
{
"data": {
"text/plain": "KNeighborsClassifier()",
"text/html": "<style>#sk-container-id-25 {color: black;background-color: white;}#sk-container-id-25 pre{padding: 0;}#sk-container-id-25 div.sk-toggleable {background-color: white;}#sk-container-id-25 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-25 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-25 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-25 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-25 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-25 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-25 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-25 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-25 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-25 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-25 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-25 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-25 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-25 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-25 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-25 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-25 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-25 div.sk-item {position: relative;z-index: 1;}#sk-container-id-25 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-25 div.sk-item::before, #sk-container-id-25 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-25 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-25 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-25 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-25 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-25 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-25 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-25 div.sk-label-container {text-align: center;}#sk-container-id-25 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-25 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-25\" 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-25\" type=\"checkbox\" checked><label for=\"sk-estimator-id-25\" 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": 269,
"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:49:55.315007Z",
"start_time": "2023-05-18T01:49:55.303883Z"
}
}
},
{
"cell_type": "code",
"execution_count": 270,
"outputs": [],
"source": [
"predicted=gnb.predict((X_test).toarray())\n",
"expected = y_test"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-05-18T01:49:55.330297Z",
"start_time": "2023-05-18T01:49:55.311459Z"
}
}
},
{
"cell_type": "code",
"execution_count": 271,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"20.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:49:55.357313Z",
"start_time": "2023-05-18T01:49:55.326780Z"
}
}
},
{
"cell_type": "code",
"execution_count": 272,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 20.00%\n"
]
}
],
"source": [
"print(f'{gnb.score((X_test).toarray(), y_test): .2%}')"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-05-18T01:49:55.362376Z",
"start_time": "2023-05-18T01:49:55.341241Z"
}
}
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
{
"cells": [
{
"cell_type": "code",
"execution_count": 257,
"metadata": {
"collapsed": true,
"ExecuteTime": {
"end_time": "2023-05-18T01:49:38.014295Z",
"start_time": "2023-05-18T01:49:38.007387Z"
}
},
"outputs": [],
"source": [
"import edn_format as edn\n",
"from sklearn.model_selection import train_test_split\n",
"from sklearn.feature_extraction.text import CountVectorizer\n",
"vectorizer = CountVectorizer()\n",
"analyze = vectorizer.build_analyzer()"
]
},
{
"cell_type": "code",
"execution_count": 258,
"outputs": [],
"source": [
"data = vectorizer.fit_transform(edn.loads(open(\"sample_data.txt\").read()))\n",
"target = edn.loads(open(\"sample_expected.txt\").read())"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-05-18T01:49:38.035222Z",
"start_time": "2023-05-18T01:49:38.012819Z"
}
}
},
{
"cell_type": "code",
"execution_count": 259,
"outputs": [],
"source": [
"X_train, X_test, y_train, y_test = train_test_split(data, target, test_size=0.2, random_state=1999)"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-05-18T01:49:38.048317Z",
"start_time": "2023-05-18T01:49:38.038940Z"
}
}
},
{
"cell_type": "code",
"execution_count": 260,
"outputs": [],
"source": [
"from sklearn.neighbors import KNeighborsClassifier"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-05-18T01:49:38.053101Z",
"start_time": "2023-05-18T01:49:38.046545Z"
}
}
},
{
"cell_type": "code",
"execution_count": 261,
"outputs": [
{
"data": {
"text/plain": "GaussianNB()",
"text/html": "<style>#sk-container-id-24 {color: black;background-color: white;}#sk-container-id-24 pre{padding: 0;}#sk-container-id-24 div.sk-toggleable {background-color: white;}#sk-container-id-24 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-24 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-24 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-24 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-24 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-24 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-24 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-24 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-24 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-24 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-24 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-24 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-24 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-24 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-24 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-24 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-24 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-24 div.sk-item {position: relative;z-index: 1;}#sk-container-id-24 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-24 div.sk-item::before, #sk-container-id-24 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-24 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-24 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-24 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-24 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-24 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-24 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-24 div.sk-label-container {text-align: center;}#sk-container-id-24 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-24 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-24\" 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-24\" type=\"checkbox\" checked><label for=\"sk-estimator-id-24\" 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": 261,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"knc = KNeighborsClassifier()\n",
"knc.fit(X_train, y_train)"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-05-18T01:49:38.074733Z",
"start_time": "2023-05-18T01:49:38.058388Z"
}
}
},
{
"cell_type": "code",
"execution_count": 262,
"outputs": [],
"source": [
"predicted=knc.predict(X_test)\n",
"expected = y_test"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-05-18T01:49:38.086974Z",
"start_time": "2023-05-18T01:49:38.072132Z"
}
}
},
{
"cell_type": "code",
"execution_count": 263,
"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:49:38.087358Z",
"start_time": "2023-05-18T01:49:38.077370Z"
}
}
},
{
"cell_type": "code",
"execution_count": 264,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 65.00%\n"
]
}
],
"source": [
"print(f'{knc.score(X_test, y_test): .2%}')"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-05-18T01:49:38.090517Z",
"start_time": "2023-05-18T01:49:38.085248Z"
}
}
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
{
"cells": [
{
"cell_type": "code",
"execution_count": 366,
"metadata": {
"collapsed": true,
"ExecuteTime": {
"end_time": "2023-05-18T01:53:55.666452Z",
"start_time": "2023-05-18T01:53:55.643356Z"
}
},
"outputs": [],
"source": [
"import edn_format as edn\n",
"from sklearn.model_selection import train_test_split\n",
"from sklearn.feature_extraction.text import CountVectorizer\n",
"vectorizer = CountVectorizer()\n",
"analyze = vectorizer.build_analyzer()"
]
},
{
"cell_type": "code",
"execution_count": 367,
"outputs": [],
"source": [
"data = vectorizer.fit_transform(edn.loads(open(\"sample_data.txt\").read()))\n",
"target = edn.loads(open(\"sample_expected.txt\").read())"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-05-18T01:53:55.696031Z",
"start_time": "2023-05-18T01:53:55.660318Z"
}
}
},
{
"cell_type": "code",
"execution_count": 368,
"outputs": [],
"source": [
"X_train, X_test, y_train, y_test = train_test_split(data, target, test_size=0.2, random_state=1999)"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-05-18T01:53:55.703863Z",
"start_time": "2023-05-18T01:53:55.699895Z"
}
}
},
{
"cell_type": "code",
"execution_count": 369,
"outputs": [],
"source": [
"from sklearn.svm import SVC"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-05-18T01:53:55.709149Z",
"start_time": "2023-05-18T01:53:55.705840Z"
}
}
},
{
"cell_type": "code",
"execution_count": 370,
"outputs": [
{
"data": {
"text/plain": "SVC()",
"text/html": "<style>#sk-container-id-37 {color: black;background-color: white;}#sk-container-id-37 pre{padding: 0;}#sk-container-id-37 div.sk-toggleable {background-color: white;}#sk-container-id-37 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-37 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-37 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-37 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-37 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-37 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-37 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-37 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-37 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-37 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-37 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-37 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-37 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-37 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-37 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-37 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-37 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-37 div.sk-item {position: relative;z-index: 1;}#sk-container-id-37 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-37 div.sk-item::before, #sk-container-id-37 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-37 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-37 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-37 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-37 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-37 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-37 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-37 div.sk-label-container {text-align: center;}#sk-container-id-37 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-37 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-37\" 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-37\" type=\"checkbox\" checked><label for=\"sk-estimator-id-37\" 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": 370,
"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:53:55.729099Z",
"start_time": "2023-05-18T01:53:55.719679Z"
}
}
},
{
"cell_type": "code",
"execution_count": 371,
"outputs": [],
"source": [
"predicted=svc.predict(X_test)\n",
"expected = y_test"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-05-18T01:53:55.733844Z",
"start_time": "2023-05-18T01:53:55.730968Z"
}
}
},
{
"cell_type": "code",
"execution_count": 372,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"35.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:53:55.738217Z",
"start_time": "2023-05-18T01:53:55.735115Z"
}
}
},
{
"cell_type": "code",
"execution_count": 373,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 35.00%\n"
]
}
],
"source": [
"print(f'{svc.score(X_test, y_test): .2%}')"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-05-18T01:53:55.744380Z",
"start_time": "2023-05-18T01:53:55.740566Z"
}
}
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
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