{ "info": { "author": "Helena A. Gaspar", "author_email": "hagax8@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "tutorial\n========\n\nsklearn integration\n-------------------\n\nugtm v2.0 provides sklearn-compatible GTM transformer (eGTM), GTM classifier (eGTC) and GTM regressor (eGTR)::\n\n\n from ugtm import eGTM, eGTC, eGTR\n import numpy as np\n\n # Dummy train and test\n X_train = np.random.randn(100, 50)\n X_test = np.random.randn(50, 50)\n y_train = np.random.choice([1, 2, 3], size=100)\n\n # GTM transformer\n transformed = eGTM().fit(X_train).transform(X_test)\n\n # Predict new labels using GTM classifier (GTC)\n predicted_labels = eGTC().fit(X_train, y_train).predict(X_test)\n\n # Predict new continuous outcomes using GTM regressor (GTR) \n predicted_labels = eGTR().fit(X_train, y_train).predict(X_test)\n\n\nThe following sections will show functions no defined within the sklearn framework.\n\n\nBasic functions\n---------------\n\nugtm provides an implementation of GTM (Generative Topographic Mapping), kGTM (kernel Generative Topographic Mapping), GTM classification models (kNN, Bayes) and GTM regression models. ugtm also implements cross-validation options which can be used to compare GTM classification models to SVM classification models, and GTM regression models to SVM regression models. Typical usage::\n\n #!/usr/bin/env python\n\n import ugtm \n import numpy as np\n \n #generate sample data and labels: replace this with your own data\n data=np.random.randn(100,50)\n labels=np.random.choice([1,2],size=100)\n\n #build GTM map\n gtm=ugtm.runGTM(data=data,verbose=True)\n\n #plot GTM map (html)\n gtm.plot_html(output=\"out\")\n\nFor installation instructions, cf. https://github.com/hagax8/ugtm\n\n\nConstruct and plot GTM maps (or kGTM maps)\n------------------------------------------\n\nA gtm object can be created by running the function runGTM on a dataset. Parameters for runGTM are: k = sqrt(number of nodes), m = sqrt(number of rbf centres), s = RBF width factor, regul = regularization coefficient. The number of iteration for the expectation-maximization algorithm is set to 200 by default. This is an example with random data::\n\n import ugtm\n \n #import numpy to generate random data\n import numpy as np\n\n #generate random data (independent variables x), \n #discrete labels (dependent variable y),\n #and continuous labels (dependent variable y), \n #to experiment with categorical or continuous outcomes\n \n train = np.random.randn(20,10)\n test = np.random.randn(20,10)\n labels=np.random.choice([\"class1\",\"class2\"],size=20)\n activity=np.random.randn(20,1)\n\n #create a gtm object and write model\n gtm = ugtm.runGTM(train)\n gtm.write(\"testout1\")\n\n #run verbose\n gtm = ugtm.runGTM(train, verbose=True)\n\n #to run a kernel GTM model instead, run following:\n gtm = ugtm.runkGTM(train, doKernel=True, kernel=\"linear\")\n\n #access coordinates (means or modes), and responsibilities of gtm object\n gtm_coordinates = gtm.matMeans\n gtm_modes = gtm.matModes\n gtm_responsibilities = gtm.matR\n\n\n\nPlot html maps\n--------------\n\nCall the plot_html() function on the gtm object::\n\n #run model on train\n gtm = ugtm.runGTM(train)\n\n # ex. plot gtm object with landscape, html: labels are continuous\n gtm.plot_html(output=\"testout10\",labels=activity,discrete=False,pointsize=20)\n\n # ex. plot gtm object with landscape, html: labels are discrete\n gtm.plot_html(output=\"testout11\",labels=labels,discrete=True,pointsize=20)\n\n # ex. plot gtm object with landscape, html: labels are continuous\n # no interpolation between nodes\n gtm.plot_html(output=\"testout12\",labels=activity,discrete=False,pointsize=20, \\\n do_interpolate=False,ids=labels)\n\n # ex. plot gtm object with landscape, html: labels are discrete, \n # no interpolation between nodes\n gtm.plot_html(output=\"testout13\",labels=labels,discrete=True,pointsize=20, \\\n do_interpolate=False)\n\n\nPlot pdf maps\n-------------\n\nCall the plot() function on the gtm object::\n\n #run model on train\n gtm = ugtm.runGTM(train)\n\n # ex. plot gtm object, pdf: no labels\n gtm.plot(output=\"testout6\",pointsize=20)\n\n # ex. plot gtm object with landscape, pdf: labels are discrete\n gtm.plot(output=\"testout7\",labels=labels,discrete=True,pointsize=20)\n\n # ex. plot gtm object with landscape, pdf: labels are continuous\n gtm.plot(output=\"testout8\",labels=activity,discrete=False,pointsize=20)\n\n\n\nPlot multipanel views\n---------------------\n\nCall the plot_multipanel() function on the gtm object.\nThis plots a general model view, showing means, modes, landscape with or without points.\nThe plot_multipanel function only works if you have defined labels::\n\n #run model on train\n gtm = ugtm.runGTM(train)\n\n # ex. with discrete labels and inter-node interpolation\n gtm.plot_multipanel(output=\"testout2\",labels=labels,discrete=True,pointsize=20)\n\n # ex. with continuous labels and inter-node interpolation\n gtm.plot_multipanel(output=\"testout3\",labels=activity,discrete=False,pointsize=20)\n\n # ex. with discrete labels and no inter-node interpolation\n gtm.plot_multipanel(output=\"testout4\",labels=labels,discrete=True,pointsize=20, \\\n do_interpolate=False)\n\n # ex. with continuous labels and no inter-node interpolation\n gtm.plot_multipanel(output=\"testout5\",labels=activity,discrete=False,pointsize=20, \\\n do_interpolate=False)\n\n\nProject new data onto existing GTM map\n--------------------------------------\n\nNew data can be projected on the GTM map by using the transform() function, which takes as input the gtm model, a training and test set. The train set is then only used to perform data preprocessing on the test set based on the train (for example: apply the same PCA transformation to the train and test sets before running the algorithm)::\n\n #run model on train\n gtm = ugtm.runGTM(train,doPCA=True)\n\n #test new data (test)\n transformed=ugtm.transform(optimizedModel=gtm,train=train,test=test,doPCA=True)\n\n #plot transformed test (html)\n transformed.plot_html(output=\"testout14\",pointsize=20)\n\n #plot transformed test (pdf)\n transformed.plot(output=\"testout15\",pointsize=20)\n\n #plot transformed data on existing classification model, \n #using training set labels\n gtm.plot_html_projection(output=\"testout16\",projections=transformed,\\\n labels=labels, \\\n discrete=True,pointsize=20)\n\n\n7. Output predictions for a test set: GTM regression (GTR) and classification (GTC)\n====================================================================================\n\nThe GTR() function implements the GTM regression model (cf. references) and GTC() function a GTM classification model (cf. references)::\n\n #continuous labels (prediction by GTM regression model)\n predicted=ugtm.GTR(train=train,test=test,labels=activity)\n\n #discrete labels (prediction by GTM classification model)\n predicted=ugtm.GTC(train=train,test=test,labels=labels)\n\n\n8. Advanced GTM predictions with per-class probabilities\n=========================================================\n\nPer-class probabilities for a test set can be given by the advancedGTC() function (you can set the m, k, regul, s parameters just as with runGTM)::\n\n #get whole output model and label predictions for test set\n predicted_model=ugtm.advancedGTC(train=train,test=test,labels=labels)\n\n #write whole predicted model with per-class probabilities\n ugtm.printClassPredictions(predicted_model,\"testout17\")\n\n\n\n9. Crossvalidation experiments\n==============================\n\nDifferent crossvalidation experiments were implemented to compare GTC and GTR models to classical machine learning methods::\n\n #crossvalidation experiment: GTM classification model implemented in ugtm, \n #here: set hyperparameters s=1 and regul=1 (set to -1 to optimize)\n ugtm.crossvalidateGTC(data=train,labels=labels,s=1,regul=1,n_repetitions=10,n_folds=5)\n\n #crossvalidation experiment: GTM regression model\n ugtm.crossvalidateGTR(data=train,labels=activity,s=1,regul=1)\n\n #you can also run the following functions to compare\n #with other classification/regression algorithms:\n\n #crossvalidation experiment, k-nearest neighbours classification\n #on 2D PCA map with 7 neighbors (set to -1 to optimize number of neighbours)\n ugtm.crossvalidatePCAC(data=train,labels=labels,n_neighbors=7)\n\n #crossvalidation experiment, SVC rbf classification model (sklearn implementation):\n ugtm.crossvalidateSVCrbf(data=train,labels=labels,C=1,gamma=1)\n\n #crossvalidation experiment, linear SVC classification model (sklearn implementation):\n ugtm.crossvalidateSVC(data=train,labels=labels,C=1)\n\n #crossvalidation experiment, linear SVC regression model (sklearn implementation):\n ugtm.crossvalidateSVR(data=train,labels=activity,C=1,epsilon=1)\n\n #crossvalidation experiment, k-nearest neighbours regression on 2D PCA map with 7 neighbors:\n ugtm.crossvalidatePCAR(data=train,labels=activity,n_neighbors=7)\n\n\n\n10. Links & references\n=======================\n\n1. GTM algorithm by Bishop et al: https://www.microsoft.com/en-us/research/wp-content/uploads/1998/01/bishop-gtm-ncomp-98.pdf\n\n2. kernel GTM: https://www.elen.ucl.ac.be/Proceedings/esann/esannpdf/es2010-44.pdf\n\n3. GTM classification models: https://www.ncbi.nlm.nih.gov/pubmed/24320683\n\n4. GTM regression models: https://www.ncbi.nlm.nih.gov/pubmed/27490381\n\n5. github: https://github.com/hagax8/ugtm", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/hagax8/ugtm", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "ugtm", "package_url": "https://pypi.org/project/ugtm/", "platform": "", "project_url": "https://pypi.org/project/ugtm/", "project_urls": { "Homepage": "http://github.com/hagax8/ugtm" }, "release_url": "https://pypi.org/project/ugtm/2.0.0/", "requires_dist": null, "requires_python": "", "summary": "Generative Topographic Mapping (GTM) for python, GTM classification and GTM regression", "version": "2.0.0" }, "last_serial": 4491318, "releases": { "1.1.4": [ { "comment_text": "", "digests": { "md5": "ef22fa7d4d61190a97d64cb255aec8ab", "sha256": "83c657ab475e07a8a029474856127f2cf5ce74179e91c33b4b53af77f857135b" }, "downloads": -1, "filename": "ugtm-1.1.4.tar.gz", "has_sig": false, "md5_digest": "ef22fa7d4d61190a97d64cb255aec8ab", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 20818, "upload_time": "2018-06-01T03:06:10", "url": "https://files.pythonhosted.org/packages/aa/26/2c781ae619b97147855c6c601ed8b61fe04887da93b6a1814fe38713ee3c/ugtm-1.1.4.tar.gz" } ], "1.1.5": [ { "comment_text": "", "digests": { "md5": "d1204e22a5f0e246c0a40fd5573e768c", "sha256": "12673a9a02c6979d72c95b28a1f928224c05c9325681f3beddc137636899fc21" }, "downloads": -1, "filename": "ugtm-1.1.5.tar.gz", "has_sig": false, "md5_digest": "d1204e22a5f0e246c0a40fd5573e768c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 20856, "upload_time": "2018-07-13T14:10:00", "url": "https://files.pythonhosted.org/packages/9a/36/6b1b46ae618ee663b8eddcbcacdd34a0163439cb79493490c7cc7d8e8751/ugtm-1.1.5.tar.gz" } ], "1.1.6": [ { "comment_text": "", "digests": { "md5": "7e91a0ff95d3df72b59ad4f9bb5243c0", "sha256": "a2836bfbbfd4b9528b6d1a2ef8b3eb21e58fa77452e1a695d55b6d8ff8a7e1bc" }, "downloads": -1, "filename": "ugtm-1.1.6.tar.gz", "has_sig": false, "md5_digest": "7e91a0ff95d3df72b59ad4f9bb5243c0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 20888, "upload_time": "2018-07-13T15:04:49", "url": "https://files.pythonhosted.org/packages/b5/79/171baf3ac4a68d14b2b6e42501b5b6521dbbe465406344170b719eba62ac/ugtm-1.1.6.tar.gz" } ], "1.1.7": [ { "comment_text": "", "digests": { "md5": "cb70b32bd85105dc91cd3334d2a00ede", "sha256": "47c4ea75085c284ac5f4750e9448c215961c9afe7229fdd703f284a3e1a3982b" }, "downloads": -1, "filename": "ugtm-1.1.7.tar.gz", "has_sig": false, "md5_digest": "cb70b32bd85105dc91cd3334d2a00ede", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 20939, "upload_time": "2018-10-24T14:28:14", "url": "https://files.pythonhosted.org/packages/4f/d9/cbe56e1eea09209b939b47ba33d335c400a8d34369a69d671fa6d13ff86d/ugtm-1.1.7.tar.gz" } ], "1.1.8": [ { "comment_text": "", "digests": { "md5": "d82d4ec00627607ff226b8478d51747c", "sha256": "197bebcbef9cbea20330750c268b609674098d3a9c548296c40b5f8ccc8b4e3f" }, "downloads": -1, "filename": "ugtm-1.1.8.tar.gz", "has_sig": false, "md5_digest": "d82d4ec00627607ff226b8478d51747c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 20908, "upload_time": "2018-11-05T15:59:29", "url": "https://files.pythonhosted.org/packages/e4/55/b59d3d8ae4fff91d907f83055807067c8e2e4f12e6709601cc8880a87ff6/ugtm-1.1.8.tar.gz" } ], "2.0.0": [ { "comment_text": "", "digests": { "md5": "3d28504d55c3c22f14e885d766bc4450", "sha256": "b409ca5630a1a0b0579b57ea1e4ca92c45e6f8286ee62f886526451fc932f3b4" }, "downloads": -1, "filename": "ugtm-2.0.0.tar.gz", "has_sig": false, "md5_digest": "3d28504d55c3c22f14e885d766bc4450", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 48056, "upload_time": "2018-11-15T21:26:17", "url": "https://files.pythonhosted.org/packages/23/40/b156dbc6006f1d94c89b3cb7ebb3c2864001cd2340f23c47733288679773/ugtm-2.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "3d28504d55c3c22f14e885d766bc4450", "sha256": "b409ca5630a1a0b0579b57ea1e4ca92c45e6f8286ee62f886526451fc932f3b4" }, "downloads": -1, "filename": "ugtm-2.0.0.tar.gz", "has_sig": false, "md5_digest": "3d28504d55c3c22f14e885d766bc4450", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 48056, "upload_time": "2018-11-15T21:26:17", "url": "https://files.pythonhosted.org/packages/23/40/b156dbc6006f1d94c89b3cb7ebb3c2864001cd2340f23c47733288679773/ugtm-2.0.0.tar.gz" } ] }