{ "info": { "author": "V\u00e1clav \u010cadek", "author_email": "vaclavcadek@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "Intended Audience :: Science/Research", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3 :: Only", "Topic :: Software Development :: Libraries", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "keras2pmml\r\n==========\r\n\r\nKeras2pmml is simple exporter for Keras models (for supported models see bellow) into PMML text format which address\r\nthe problems mentioned bellow.\r\n\r\nStoring predictive models using binary format (e.g. Pickle) may be dangerous from several perspectives - naming few:\r\n\r\n* **binary compatibility**:you update the libraries and may not be able to open the model serialized with older version\r\n* **dangerous code**: when you would use model made by someone else\r\n* **interpretability**: model cannot be easily opened and reviewed by human\r\n* etc.\r\n\r\nIn addition the PMML is able to persist scaling of the raw input features which helps gradient descent to run smoothly through optimization space.\r\n\r\nInstallation\r\n------------\r\n\r\nTo install keras2pmml, simply:\r\n\r\n.. code-block:: bash\r\n\r\n $ pip install keras2pmml\r\n\r\nExample\r\n-------\r\n\r\nExample on Iris data - for more examples see the examples folder.\r\n\r\n.. code-block:: python\r\n\r\n from keras2pmml import keras2pmml\r\n from sklearn.datasets import load_iris\r\n import numpy as np\r\n import theano\r\n from sklearn.cross_validation import train_test_split\r\n from sklearn.preprocessing import StandardScaler\r\n from keras.utils import np_utils\r\n from keras.models import Sequential\r\n from keras.layers.core import Dense\r\n\r\n iris = load_iris()\r\n X = iris.data\r\n y = iris.target\r\n\r\n theano.config.floatX = 'float32'\r\n X = X.astype(theano.config.floatX)\r\n y = y.astype(np.int32)\r\n\r\n X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=.3)\r\n\r\n std = StandardScaler()\r\n X_train_scaled = std.fit_transform(X_train)\r\n X_test_scaled = std.transform(X_test)\r\n y_train_ohe = np_utils.to_categorical(y_train)\r\n y_test_ohe = np_utils.to_categorical(y_test)\r\n\r\n model = Sequential()\r\n model.add(Dense(input_dim=X_train.shape[1], output_dim=5, activation='tanh'))\r\n model.add(Dense(input_dim=5, output_dim=y_test_ohe.shape[1], activation='sigmoid'))\r\n model.compile(loss='categorical_crossentropy', optimizer='sgd')\r\n model.fit(X_train_scaled, y_train_ohe, nb_epoch=10, batch_size=1, verbose=3,\r\n validation_data=(X_test_scaled, y_test_ohe))\r\n\r\n params = {\r\n 'feature_names': ['sepal_length', 'sepal_width', 'petal_length', 'petal_width'],\r\n 'target_values': ['setosa', 'virginica', 'versicolor'],\r\n 'target_name': 'specie',\r\n 'copyright': 'V\u00e1clav \u010cadek',\r\n 'description': 'Simple Keras model for Iris dataset.',\r\n 'model_name': 'Iris Model'\r\n }\r\n\r\n keras2pmml(estimator=model, transformer=std, file='keras_iris.pmml', **params)\r\n\r\n\r\n\r\nParams explained\r\n----------------\r\n- **estimator**: Keras model to be exported as PMML (for supported models - see bellow).\r\n- **transformer**: if provided (and it's supported - see bellow) then scaling is applied to data fields.\r\n- **file**: name of the file where the PMML will be exported.\r\n- **feature_names**: when provided and have same shape as input layer, then features will have custom names, otherwise generic names (x\\ :sub:`0`\\,..., x\\ :sub:`n-1`\\) will be used.\r\n- **target_values**: when provided and have same shape as output layer, then target values will have custom names, otherwise generic names (y\\ :sub:`0`\\,..., y\\ :sub:`n-1`\\) will be used.\r\n- **target_name**: when provided then target variable will have custom name, otherwise generic name **class** will be used.\r\n- **copyright**: who is the author of the model.\r\n- **description**: optional parameter that sets *description* within PMML document.\r\n- **model_name**: optional parameter that sets *model_name* within PMML document.\r\n\r\nWhat is supported?\r\n------------------\r\n- Models\r\n * keras.models.Sequential\r\n- Activation functions\r\n * tanh\r\n * sigmoid/logistic\r\n- Scalers\r\n * sklearn.preprocessing.StandardScaler\r\n * sklearn.preprocessing.MinMaxScaler\r\n\r\nLicense\r\n-------\r\n\r\nThis software is licensed under MIT licence.\r\n\r\n- https://opensource.org/licenses/MIT", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/vaclavcadek/keras2pmml", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "keras2pmml", "package_url": "https://pypi.org/project/keras2pmml/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/keras2pmml/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/vaclavcadek/keras2pmml" }, "release_url": "https://pypi.org/project/keras2pmml/0.1.0/", "requires_dist": null, "requires_python": null, "summary": "Simple exporter of Keras models into PMML", "version": "0.1.0" }, "last_serial": 2251136, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "9cb603e54274f6095b3dd4915ee33921", "sha256": "2af5a5a5824b0bdcb864eb83a7e7dd2d7a6ae1cad73c7b8f5dc4d1b6f06db3df" }, "downloads": -1, "filename": "keras2pmml-0.1.0.tar.gz", "has_sig": false, "md5_digest": "9cb603e54274f6095b3dd4915ee33921", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4974, "upload_time": "2016-07-25T09:07:37", "url": "https://files.pythonhosted.org/packages/27/3a/b18e5936899dd2ab327ec687aa2001fb5fb48a87230806b828be983f9554/keras2pmml-0.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "9cb603e54274f6095b3dd4915ee33921", "sha256": "2af5a5a5824b0bdcb864eb83a7e7dd2d7a6ae1cad73c7b8f5dc4d1b6f06db3df" }, "downloads": -1, "filename": "keras2pmml-0.1.0.tar.gz", "has_sig": false, "md5_digest": "9cb603e54274f6095b3dd4915ee33921", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4974, "upload_time": "2016-07-25T09:07:37", "url": "https://files.pythonhosted.org/packages/27/3a/b18e5936899dd2ab327ec687aa2001fb5fb48a87230806b828be983f9554/keras2pmml-0.1.0.tar.gz" } ] }