Skip to content

Commit

Permalink
updated notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
claesenm committed Jul 9, 2015
1 parent 9bb7ed6 commit 061d509
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 28 deletions.
28 changes: 11 additions & 17 deletions docs/notebooks/notebooks/sklearn-svc.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

Tuning a scikit-learn SVM classifier
====================================

In this example we will use Optunity to optimize hyperparameters for a
support vector machine classifier (SVC) in scikit-learn. We will learn a
model to distinguish digits 8 and 9 in the MNIST data set in two
Expand Down Expand Up @@ -55,12 +58,12 @@ First, lets see the performance of an SVC with default hyperparameters.
.. parsed-literal::
0.6817249486770811
0.7838539081885857
Tune SVC with RBF kernel
=========================
-------------------------

In order to use Optunity to optimize hyperparameters, we start by
defining the objective function. We will use 5-fold cross-validated area
Expand Down Expand Up @@ -110,12 +113,12 @@ Now we can use Optunity to find the hyperparameters that maximize AUROC.
.. parsed-literal::
Optimal parameters: {'C': 2.7282633076523837, 'gamma': 0.0003793484996538702}
AUROC of tuned SVM with RBF kernel: 0.981
Optimal parameters: {'C': 5.145039160286679, 'gamma': 0.0011649329771152538}
AUROC of tuned SVM with RBF kernel: 0.985
Tune SVC without deciding the kernel in advance
================================================
------------------------------------------------

In the previous part we choose to use an RBF kernel. Even though the RBF
kernel is known to work well for a large variety of problems (and
Expand Down Expand Up @@ -169,17 +172,8 @@ hyperparameters!
print("Optimal parameters" + str(optimal_svm_pars))
print("AUROC of tuned SVM: %1.3f" % info.optimum)
::


---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)

<ipython-input-8-510629d48255> in <module>()
----> 1 optimal_svm_pars, info, _ = optunity.maximize_structured(svm_tuned_auroc, space, num_evals=150)
2 print("Optimal parameters" + str(optimal_svm_pars))
3 print("AUROC of tuned SVM: %1.3f" % info.optimum)

.. parsed-literal::
AttributeError: 'module' object has no attribute 'maximize_structured'
Optimal parameters{'kernel': 'rbf', 'C': 7.919921875, 'coef0': None, 'gamma': 0.00107421875, 'degree': None}
AUROC of tuned SVM: 0.986
20 changes: 9 additions & 11 deletions notebooks/sklearn-svc.ipynb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"metadata": {
"name": "",
"signature": "sha256:a1f6146842bf7ec231af71435516d6b7921e86d3dd5698060e0cd6fbde5bf65e"
"signature": "sha256:b612a358c9e392e8474fa3ac13e0e29107507c7fd42cccd42be68cf3f94feb02"
},
"nbformat": 3,
"nbformat_minor": 0,
Expand Down Expand Up @@ -104,7 +104,7 @@
"output_type": "pyout",
"prompt_number": 3,
"text": [
"0.6817249486770811"
"0.7838539081885857"
]
}
],
Expand Down Expand Up @@ -187,8 +187,8 @@
"output_type": "stream",
"stream": "stdout",
"text": [
"Optimal parameters: {'C': 2.7282633076523837, 'gamma': 0.0003793484996538702}\n",
"AUROC of tuned SVM with RBF kernel: 0.981\n"
"Optimal parameters: {'C': 5.145039160286679, 'gamma': 0.0011649329771152538}\n",
"AUROC of tuned SVM with RBF kernel: 0.985\n"
]
}
],
Expand Down Expand Up @@ -281,13 +281,11 @@
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "'module' object has no attribute 'maximize_structured'",
"output_type": "pyerr",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-8-510629d48255>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0moptimal_svm_pars\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minfo\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0m_\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0moptunity\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmaximize_structured\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msvm_tuned_auroc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mspace\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnum_evals\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m150\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0;32mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Optimal parameters\"\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0moptimal_svm_pars\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;32mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"AUROC of tuned SVM: %1.3f\"\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0minfo\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0moptimum\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mAttributeError\u001b[0m: 'module' object has no attribute 'maximize_structured'"
"output_type": "stream",
"stream": "stdout",
"text": [
"Optimal parameters{'kernel': 'rbf', 'C': 7.919921875, 'coef0': None, 'gamma': 0.00107421875, 'degree': None}\n",
"AUROC of tuned SVM: 0.986\n"
]
}
],
Expand Down

0 comments on commit 061d509

Please sign in to comment.