Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
595 changes: 554 additions & 41 deletions your-code/lab_boston_housing.ipynb

Large diffs are not rendered by default.

162 changes: 145 additions & 17 deletions your-code/lab_overfitting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -55,13 +55,28 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n"
"# Your code here\n",
"from sklearn.svm import SVC\n",
"gamma_values = [0.001, 1, 20]\n",
"\n",
"svm_classifiers = []\n",
"for gamma in gamma_values:\n",
" svm = SVC(kernel='rbf', gamma=gamma)\n",
" svm_classifiers.append(svm)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -71,9 +86,30 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "NameError",
"evalue": "name 'classifiers' is not defined",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_4004\\2435835255.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 14\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 15\u001b[0m \u001b[1;31m# iterate over classifiers\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 16\u001b[1;33m \u001b[1;32mfor\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mclf\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mzip\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnames\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mclassifiers\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 17\u001b[0m \u001b[0max\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mplt\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msubplot\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mclassifiers\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mi\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 18\u001b[0m \u001b[0mclf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mX\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0my\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mNameError\u001b[0m: name 'classifiers' is not defined"
]
},
{
"data": {
"text/plain": [
"<Figure size 1200x600 with 0 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from matplotlib.colors import ListedColormap\n",
"\n",
Expand Down Expand Up @@ -146,13 +182,45 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1.0\n"
]
}
],
"source": [
"# Your code here"
"# Your code here\n",
"from sklearn.svm import SVC\n",
"from sklearn.datasets import make_classification\n",
"\n",
"\n",
"X, y = make_classification(n_features=2, n_redundant=0, n_informative=2,\n",
" random_state=42, n_clusters_per_class=1)\n",
"\n",
"\n",
"clf = SVC(kernel='rbf', gamma=0.7)\n",
"\n",
"\n",
"clf.fit(X, y)\n",
"\n",
"\n",
"accuracy = clf.score(X, y)\n",
"\n",
"print(accuracy)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -162,13 +230,41 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1.0\n"
]
}
],
"source": [
"# Your code here"
"# Your code here\n",
"\n",
"from sklearn.model_selection import train_test_split\n",
"X, y = make_classification(n_features=2, n_redundant=0, n_informative=2,\n",
" random_state=1, n_clusters_per_class=1)\n",
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=1)\n",
"\n",
"clf = SVC(kernel='rbf', gamma=20)\n",
"\n",
"clf.fit(X_train, y_train)\n",
"\n",
"accuracy = clf.score(X_test, y_test)\n",
"\n",
"print(accuracy)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -178,13 +274,44 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.4666666666666667\n",
"1.0\n",
"1.0\n"
]
}
],
"source": [
"# Your code here"
"# Your code here\n",
"X, y = make_classification(n_features=2, n_redundant=0, n_informative=2,\n",
" random_state=1, n_clusters_per_class=1)\n",
"\n",
"\n",
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=1)\n",
"classifiers = [\n",
" SVC(kernel='rbf', gamma=0.001),\n",
" SVC(kernel='rbf', gamma=1),\n",
" SVC(kernel='rbf', gamma=20)\n",
"]\n",
"for clf in classifiers:\n",
" clf.fit(X_train, y_train)\n",
" accuracy = clf.score(X_test, y_test)\n",
" print(accuracy)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -198,13 +325,14 @@
"metadata": {},
"outputs": [],
"source": [
"# Your response here"
"# Your response here\n",
"#Ensemble method ou cross validations for example"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -218,7 +346,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
"version": "3.9.13"
}
},
"nbformat": 4,
Expand Down