Skip to content

Instantly share code, notes, and snippets.

@Neeratyoy
Created October 23, 2019 15:56
Show Gist options
  • Save Neeratyoy/d5a08cfb8f8eac482b4bb517e658b668 to your computer and use it in GitHub Desktop.
Save Neeratyoy/d5a08cfb8f8eac482b4bb517e658b668 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import openml\n",
"import numpy as np\n",
"from sklearn.svm import NuSVC"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# Building the NuSVC model object with parameters found\n",
"clf = NuSVC(cache_size=200, class_weight=None, coef0=0.0,\n",
" decision_function_shape=None, degree=3, gamma='auto', kernel='linear',\n",
" max_iter=-1, nu=0.3, probability=True, random_state=3, shrinking=True,\n",
" tol=3.2419092644286417e-05, verbose=False)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"OpenML Classification Task\n",
"==========================\n",
"Task Type Description: https://www.openml.org/tt/1\n",
"Task ID..............: 59\n",
"Task URL.............: https://www.openml.org/t/59\n",
"Estimation Procedure.: crossvalidation\n",
"Evaluation Measure...: predictive_accuracy\n",
"Target Feature.......: class\n",
"# of Classes.........: 3\n",
"Cost Matrix..........: Available"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Obtaining task used earlier\n",
"t = openml.tasks.get_task(59)\n",
"t"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"OpenML Flow\n",
"===========\n",
"Flow Name.......: sklearn.svm.classes.NuSVC\n",
"Flow Description: Nu-Support Vector Classification.\n",
"\n",
"Similar to SVC but uses a parameter to control the number of support\n",
"vectors.\n",
"\n",
"The implementation is based on libsvm.\n",
"Dependencies....: sklearn==0.21.3\n",
"numpy>=1.6.1\n",
"scipy>=0.9"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Running the model on the task\n",
"# Internally, the model will be made into \n",
"# an OpenML flow and we can choose to retrieve it\n",
"r, f = openml.runs.run_model_on_task(model=clf, task=t, upload_flow=False, return_flow=True)\n",
"f"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.9866666666666667\n"
]
}
],
"source": [
"# To obtain the score (without uploading)\n",
"## r.publish() can be used to upload these results\n",
"## need to sign-in to https://www.openml.org/\n",
"score = []\n",
"evaluations = r.fold_evaluations['predictive_accuracy'][0]\n",
"for key in evaluations:\n",
" score.append(evaluations[key])\n",
"print(np.mean(score))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment