{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "# Copyright 2019 IBM Corporation\n",
      "#\n",
      "# Licensed under the Apache License, Version 2.0 (the \"License\");\n",
      "# you may not use this file except in compliance with the License.\n",
      "# You may obtain a copy of the License at\n",
      "#\n",
      "# http://www.apache.org/licenses/LICENSE-2.0\n",
      "#\n",
      "# Unless required by applicable law or agreed to in writing, software\n",
      "# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
      "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
      "# See the License for the specific language governing permissions and\n",
      "# limitations under the License.\n",
      "\n",
      "import sklearn.svm\n",
      "import lale.docstrings\n",
      "import lale.operators\n",
      "\n",
      "class SVCImpl():\n",
      "    def __init__(self, **hyperparams):\n",
      "        self._hyperparams = hyperparams\n",
      "        self._wrapped_model = sklearn.svm.SVC(**self._hyperparams)\n",
      "\n",
      "    def fit(self, X, y=None, sample_weight=None):\n",
      "        self._wrapped_model.fit(X, y, sample_weight)\n",
      "        return self\n",
      "\n",
      "    def predict(self, X):\n",
      "        return self._wrapped_model.predict(X)\n",
      "\n",
      "    def predict_proba(self, X):\n",
      "        return self._wrapped_model.predict_proba(X)\n",
      "\n",
      "    def decision_function(self, X):\n",
      "        return self._wrapped_model.decision_function(X)\n",
      "\n",
      "_hyperparams_schema = {\n",
      "    'allOf': [\n",
      "    {   'type': 'object',\n",
      "        'additionalProperties': False,\n",
      "        'required': ['kernel', 'degree', 'gamma', 'shrinking', 'tol', 'cache_size', 'max_iter', 'decision_function_shape'],\n",
      "        'relevantToOptimizer': ['kernel', 'degree', 'gamma', 'shrinking', 'probability', 'tol'],\n",
      "        'properties': {\n",
      "            'C': {\n",
      "                'description': 'Penalty parameter C of the error term.',\n",
      "                'type': 'number',\n",
      "                'distribution': 'loguniform',\n",
      "                'minimum': 0.0,\n",
      "                'exclusiveMinimum': True,\n",
      "                'default': 1.0,\n",
      "                'minimumForOptimizer': 0.03125,\n",
      "                'maximumForOptimizer': 32768},\n",
      "            'kernel': {\n",
      "                'anyOf': [\n",
      "                {   'enum':['precomputed'], 'forOptimizer': False}, \n",
      "                {   'enum': ['linear', 'poly', 'rbf', 'sigmoid']},\n",
      "                {   'laleType': 'callable', 'forOptimizer': False}],\n",
      "                'default': 'rbf',\n",
      "                'description':\n",
      "                    'Specifies the kernel type to be used in the algorithm.'},\n",
      "            'degree': {\n",
      "                'type': 'integer',\n",
      "                'minimum': 0,\n",
      "                'minimumForOptimizer': 2,\n",
      "                'maximumForOptimizer': 5,\n",
      "                'default': 3,\n",
      "                'description': \"Degree of the polynomial kernel function ('poly').\"},\n",
      "            'gamma': {\n",
      "                'anyOf': [\n",
      "                {   'type': 'number',\n",
      "                    'minimum': 0.0,\n",
      "                    'exclusiveMinimum': True,\n",
      "                    'minimumForOptimizer': 3.0517578125e-05,\n",
      "                    'maximumForOptimizer': 8,\n",
      "                    'distribution': 'loguniform'},\n",
      "                {   'enum': ['auto', 'auto_deprecated', 'scale']}],\n",
      "                'default': 'auto_deprecated', #going to change to 'scale' from sklearn 0.22.\n",
      "                'description': \"Kernel coefficient for 'rbf', 'poly', and 'sigmoid'.\"},\n",
      "            'coef0': {\n",
      "                'type': 'number',\n",
      "                'default': 0.0,\n",
      "                'description': 'Independent term in kernel function.'},\n",
      "            'shrinking': {\n",
      "                'type': 'boolean',\n",
      "                'default': True,\n",
      "                'description': 'Whether to use the shrinking heuristic.'},\n",
      "            'probability': {\n",
      "                'type': 'boolean',\n",
      "                'default': False,\n",
      "                'description': 'Whether to enable probability estimates.'},\n",
      "            'tol': {\n",
      "                'type': 'number',\n",
      "                'distribution': 'loguniform',\n",
      "                'minimum': 0.0,\n",
      "                'exclusiveMinimum': True,\n",
      "                'maximumForOptimizer': 0.01,\n",
      "                'default': 0.0001,\n",
      "                'description': 'Tolerance for stopping criteria.'},\n",
      "            'cache_size': {\n",
      "                'type': 'integer',\n",
      "                'default': 200,\n",
      "                'description': 'Specify the size of the kernel cache (in MB).'},\n",
      "            'class_weight': {\n",
      "                'anyOf': [\n",
      "                    { 'description': 'By default, all classes have weight 1.',\n",
      "                      'enum': [None]},\n",
      "                    { 'description': 'Adjust weights by inverse frequency.',\n",
      "                      'enum': ['balanced']},\n",
      "                    { 'description': 'Dictionary mapping class labels to weights.',\n",
      "                      'type': 'object',\n",
      "                      'additionalProperties': {'type': 'number'},\n",
      "                      'forOptimizer': False}],\n",
      "                'default': None},\n",
      "            'verbose': {\n",
      "                'type': 'boolean',\n",
      "                'default': False,\n",
      "                'description': 'Enable verbose output.'},\n",
      "            'max_iter': {\n",
      "                'type': 'integer',\n",
      "                'default': -1,\n",
      "                'description': 'Hard limit on iterations within solver, or -1 for no limit.'},\n",
      "            'decision_function_shape': {\n",
      "                'enum': ['ovo', 'ovr'],\n",
      "                'default': 'ovr',\n",
      "                'description': \"Whether to return a one-vs-rest ('ovr') decision function of shape (n_samples, n_classes) as all other classifiers, or the original one-vs-one (â€˜ovoâ€™) decision function of libsvm which has shape (n_samples, n_classes * (n_classes - 1) / 2).\"},\n",
      "            'random_state': {\n",
      "                'description':\n",
      "                'Seed of pseudo-random number generator.',\n",
      "                'anyOf': [\n",
      "                {   'laleType': 'numpy.random.RandomState'},\n",
      "                {   'description': 'RandomState used by np.random',\n",
      "                    'enum': [None]},\n",
      "                {   'description': 'Explicit seed.',\n",
      "                    'type': 'integer'}],\n",
      "                'default': None}}},\n",
      "    {   'description': 'coef0 only significant in kernel â€˜polyâ€™ and â€˜sigmoidâ€™.',\n",
      "        'anyOf': [\n",
      "        {   'type': 'object',\n",
      "            'properties': {'kernel': {'enum': ['poly', 'sigmoid']}}},\n",
      "        {   'type': 'object',\n",
      "            'properties': {'coef0': {'enum': [0.0]}}}]}]}\n",
      "\n",
      "_input_fit_schema = {\n",
      "    'type': 'object',\n",
      "    'required': ['X', 'y'],\n",
      "    'properties': {\n",
      "        'X': {\n",
      "            'type': 'array',\n",
      "            'description': 'The outer array is over samples aka rows.',\n",
      "            'items': {\n",
      "                'type': 'array',\n",
      "                'description': 'The inner array is over features aka columns.',\n",
      "                'items': {\n",
      "                    'type': 'number'}}},\n",
      "        'y': {\n",
      "            'description': 'The predicted classes.',\n",
      "            'anyOf': [\n",
      "            {   'type': 'array', 'items': {'type': 'number'}},\n",
      "            {   'type': 'array', 'items': {'type': 'string'}},\n",
      "            {   'type': 'array', 'items': {'type': 'boolean'}}]},\n",
      "        'sample_weight': {\n",
      "            'anyOf': [\n",
      "            {   'type': 'array',\n",
      "                'items': {'type': 'number'}},\n",
      "            {   'enum': [None],\n",
      "                'description': 'Samples are equally weighted.'}],\n",
      "            'description': 'Sample weights.'}}}\n",
      "\n",
      "_input_predict_schema = {\n",
      "    'type': 'object',\n",
      "    'properties': {\n",
      "        'X': {\n",
      "            'type': 'array',\n",
      "            'description': 'The outer array is over samples aka rows.',\n",
      "            'items': {\n",
      "                'type': 'array',\n",
      "                'description': 'The inner array is over features aka columns.',\n",
      "                'items': {\n",
      "                    'type': 'number'}}}}}\n",
      "\n",
      "_output_predict_schema = {\n",
      "    'description': 'The predicted classes.',\n",
      "    'anyOf': [\n",
      "    {   'type': 'array', 'items': {'type': 'number'}},\n",
      "    {   'type': 'array', 'items': {'type': 'string'}},\n",
      "    {   'type': 'array', 'items': {'type': 'boolean'}}]}\n",
      "\n",
      "_input_predict_proba_schema = {\n",
      "    'type': 'object',\n",
      "    'properties': {\n",
      "        'X': {\n",
      "            'type': 'array',\n",
      "            'description': 'The outer array is over samples aka rows.',\n",
      "            'items': {\n",
      "                'type': 'array',\n",
      "                'description': 'The inner array is over features aka columns.',\n",
      "                'items': {\n",
      "                    'type': 'number'}}}}}\n",
      "\n",
      "_output_predict_proba_schema = {\n",
      "    'type': 'array',\n",
      "    'description': 'The outer array is over samples aka rows.',\n",
      "    'items': {\n",
      "        'type': 'array',\n",
      "        'description': 'The inner array has items corresponding to each class.',\n",
      "        'items': {\n",
      "            'type': 'number'}}}\n",
      "\n",
      "_input_decision_function_schema = {\n",
      "    'type': 'object',\n",
      "    'required': ['X'],\n",
      "    'properties': {\n",
      "        'X': {\n",
      "            'type': 'array',\n",
      "            'description': 'The outer array is over samples aka rows.',\n",
      "            'items': {\n",
      "                'type': 'array',\n",
      "                'description': 'The inner array is over features aka columns.',\n",
      "                'items': {\n",
      "                    'type': 'number'}}}}}\n",
      "\n",
      "_output_decision_function_schema = {\n",
      "    'description': 'Confidence scores for samples for each class in the model.',\n",
      "    'anyOf': [\n",
      "    {   'description': 'In the multi-way case, score per (sample, class) combination.',\n",
      "        'type': 'array',\n",
      "        'items': {'type': 'array', 'items': {'type': 'number'}}},\n",
      "    {   'description': 'In the binary case, score for `self._classes[1]`.',\n",
      "        'type': 'array',\n",
      "        'items': {'type': 'number'}}]}\n",
      "\n",
      "_combined_schemas = {\n",
      "    '$schema': 'http://json-schema.org/draft-04/schema#',\n",
      "    'description': \"\"\"`Support Vector Classification`_ from scikit-learn.\n",
      "\n",
      ".. _`Support Vector Classification`: https://scikit-learn.org/0.20/modules/generated/sklearn.svm.SVC.html#sklearn-svm-svc\n",
      "\"\"\",\n",
      "    'documentation_url': 'https://lale.readthedocs.io/en/latest/modules/lale.lib.sklearn.svc.html',\n",
      "    'import_from': 'sklearn.svm',\n",
      "    'type': 'object',\n",
      "    'tags': {\n",
      "        'pre': [],\n",
      "        'op': ['estimator', 'classifier'],\n",
      "        'post': []},\n",
      "    'properties': {\n",
      "        'hyperparams': _hyperparams_schema,\n",
      "        'input_fit': _input_fit_schema,\n",
      "        'input_predict': _input_predict_schema,\n",
      "        'output_predict': _output_predict_schema,\n",
      "        'input_predict_proba': _input_predict_proba_schema,\n",
      "        'output_predict_proba': _output_predict_proba_schema,\n",
      "        'input_decision_function': _input_decision_function_schema,\n",
      "        'output_decision_function': _output_decision_function_schema}}\n",
      "\n",
      "SVC : lale.operators.IndividualOp\n",
      "SVC = lale.operators.make_operator(SVCImpl, _combined_schemas)\n",
      "\n",
      "if sklearn.__version__ >= '0.22':\n",
      "    # old: https://scikit-learn.org/0.20/modules/generated/sklearn.svm.SVC.html\n",
      "    # new: https://scikit-learn.org/0.23/modules/generated/sklearn.svm.SVC.html\n",
      "    from lale.schemas import AnyOf, Bool, Enum, Float\n",
      "    SVC = SVC.customize_schema(\n",
      "        gamma=AnyOf(\n",
      "            types=[\n",
      "                Enum(['scale', 'auto']),\n",
      "                Float(\n",
      "                    min=0.0,\n",
      "                    exclusiveMin=True,\n",
      "                    minForOptimizer=3.0517578125e-05,\n",
      "                    maxForOptimizer=8,\n",
      "                    distribution='loguniform')],\n",
      "            desc=\"Kernel coefficient for 'rbf', 'poly' and 'sigmoid'.\",\n",
      "            default='scale'),\n",
      "        break_ties=Bool(\n",
      "            desc=\"If true, decision_function_shape='ovr', and number of classes > 2, predict will break ties according to the confidence values of decision_function; otherwise the first class among the tied classes is returned.\",\n",
      "            default=False))\n",
      "\n",
      "lale.docstrings.set_docstrings(SVCImpl, SVC._schemas)\n",
      "\n"
     ]
    }
   ],
   "source": [
    "read_data = \"\"\n",
    "\n",
    "with open('svc.py') as f:\n",
    "    read_data = f.read()\n",
    "    print(read_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (<ipython-input-4-ef533c4c33c0>, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-4-ef533c4c33c0>\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m    import 'svc'\u001b[0m\n\u001b[1;37m           ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "import svc"
   ]
  }
 ],
 "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.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
