/doc/api.rst
ReStructuredText | 127 lines | 75 code | 52 blank | 0 comment | 0 complexity | cee167684092ddd0301c3de0e19ebcb1 MD5 | raw file
1.. _api:
2
3API Documentation
4=================
5
6.. _`embed model`:
7
8Embed the model
9---------------
10
11One of the most common use of the mltool API is to embed the ranker model built
12with the command line tool into your own application.
13
14The models are pickable file and you can load them using the :mod:`pickle` standard
15module:
16
17.. code-block:: python
18
19 import pickle
20 with open('model.pkl', 'rb') as fmodel:
21 model = pickle.load(fmodel)
22
23Then you can use mltool API to predict the score of a sample:
24
25.. code-block:: python
26
27 from mltool.predict import predict
28 pred = predict(model, {'f0': 1.0,
29 'f1': 0.0,
30 'f2': 0.0,
31 'f3': 0.2,
32 'f4': 1.0})
33
34Check :func:`predict <mltool.predict.predict>` and
35:func:`predict_all <mltool.predict.predict_all>` functions for more details.
36
37.. module:: mltool
38
39Prediction
40----------
41
42.. _predict:
43
44.. automodule:: mltool.predict
45
46-----------------
47
48.. autofunction:: predict
49
50-----------------
51
52.. autofunction:: predict_all
53
54.. _train:
55
56Model train
57-----------
58
59mltool implements some algorithms to train regression models.
60Currently it mainly supports Random Forest and regression trees.
61
62mltool.forest
63~~~~~~~~~~~~~
64
65.. module:: mltool.forest
66.. autofunction:: train_random_forest
67
68mltool.decisiontree
69~~~~~~~~~~~~~~~~~~~
70
71.. module:: mltool.decisiontree
72.. autofunction:: train_decision_tree
73
74
75Model Evaluation
76----------------
77
78.. _evaluate:
79
80.. automodule:: mltool.evaluate
81
82-----------------
83
84.. autofunction:: evaluate_preds
85.. autofunction:: evaluate_model
86
87
88.. _utilities:
89
90Utilities
91---------
92
93.. module:: mltool.utils
94
95.. _dataset:
96
97Handling Dataset
98~~~~~~~~~~~~~~~~
99
100.. class:: Dataset
101
102 The Dataset class is a :func:`namedtuple <collections.namedtuple>` which
103 represents a set of samples with their labels and query ids.
104
105 .. attribute:: labels
106
107 An :class:`array <numpy.array>` of labels. Each label is a `float`.
108
109 .. attribute:: queries
110
111 A list of query ids.
112
113 .. attribute:: Dataset.samples
114
115 A 2d-:class:`array <numpy.array` of samples. It consists of one sample per
116 column, and one row for each feature.
117
118 .. attribute:: Dataset.feature_names
119
120 A sequence of feature names. Features are in the same order as they appear
121 in the :attr:`samples` rows.
122
123-----------------
124
125.. autofunction:: read_input_file
126
127