/doc/api.rst

https://bitbucket.org/duilio/mltool · ReStructuredText · 127 lines · 75 code · 52 blank · 0 comment · 0 complexity · cee167684092ddd0301c3de0e19ebcb1 MD5 · raw file

  1. .. _api:
  2. API Documentation
  3. =================
  4. .. _`embed model`:
  5. Embed the model
  6. ---------------
  7. One of the most common use of the mltool API is to embed the ranker model built
  8. with the command line tool into your own application.
  9. The models are pickable file and you can load them using the :mod:`pickle` standard
  10. module:
  11. .. code-block:: python
  12. import pickle
  13. with open('model.pkl', 'rb') as fmodel:
  14. model = pickle.load(fmodel)
  15. Then you can use mltool API to predict the score of a sample:
  16. .. code-block:: python
  17. from mltool.predict import predict
  18. pred = predict(model, {'f0': 1.0,
  19. 'f1': 0.0,
  20. 'f2': 0.0,
  21. 'f3': 0.2,
  22. 'f4': 1.0})
  23. Check :func:`predict <mltool.predict.predict>` and
  24. :func:`predict_all <mltool.predict.predict_all>` functions for more details.
  25. .. module:: mltool
  26. Prediction
  27. ----------
  28. .. _predict:
  29. .. automodule:: mltool.predict
  30. -----------------
  31. .. autofunction:: predict
  32. -----------------
  33. .. autofunction:: predict_all
  34. .. _train:
  35. Model train
  36. -----------
  37. mltool implements some algorithms to train regression models.
  38. Currently it mainly supports Random Forest and regression trees.
  39. mltool.forest
  40. ~~~~~~~~~~~~~
  41. .. module:: mltool.forest
  42. .. autofunction:: train_random_forest
  43. mltool.decisiontree
  44. ~~~~~~~~~~~~~~~~~~~
  45. .. module:: mltool.decisiontree
  46. .. autofunction:: train_decision_tree
  47. Model Evaluation
  48. ----------------
  49. .. _evaluate:
  50. .. automodule:: mltool.evaluate
  51. -----------------
  52. .. autofunction:: evaluate_preds
  53. .. autofunction:: evaluate_model
  54. .. _utilities:
  55. Utilities
  56. ---------
  57. .. module:: mltool.utils
  58. .. _dataset:
  59. Handling Dataset
  60. ~~~~~~~~~~~~~~~~
  61. .. class:: Dataset
  62. The Dataset class is a :func:`namedtuple <collections.namedtuple>` which
  63. represents a set of samples with their labels and query ids.
  64. .. attribute:: labels
  65. An :class:`array <numpy.array>` of labels. Each label is a `float`.
  66. .. attribute:: queries
  67. A list of query ids.
  68. .. attribute:: Dataset.samples
  69. A 2d-:class:`array <numpy.array` of samples. It consists of one sample per
  70. column, and one row for each feature.
  71. .. attribute:: Dataset.feature_names
  72. A sequence of feature names. Features are in the same order as they appear
  73. in the :attr:`samples` rows.
  74. -----------------
  75. .. autofunction:: read_input_file