MCPcopy Index your code
hub / github.com/ddbourgin/numpy-ml / predict

Method predict

numpy_ml/trees/gbdt.py:158–181  ·  view source on GitHub ↗

Use the trained model to classify or predict the examples in `X`. Parameters ---------- X : :py:class:`ndarray ` of shape `(N, M)` The training data of `N` examples, each with `M` features Returns ------- preds : :

(self, X)

Source from the content-addressed store, hash-verified

156 Y_pred[:, k] += self.weights[i, k] * h_pred
157
158 def predict(self, X):
159 """
160 Use the trained model to classify or predict the examples in `X`.
161
162 Parameters
163 ----------
164 X : :py:class:`ndarray <numpy.ndarray>` of shape `(N, M)`
165 The training data of `N` examples, each with `M` features
166
167 Returns
168 -------
169 preds : :py:class:`ndarray <numpy.ndarray>` of shape `(N,)`
170 The integer class labels predicted for each example in `X` if
171 ``self.classifier = True``, otherwise the predicted target values.
172 """
173 Y_pred = np.zeros((X.shape[0], self.out_dims))
174 for i in range(self.n_iter):
175 for k in range(self.out_dims):
176 Y_pred[:, k] += self.weights[i, k] * self.learners[i, k].predict(X)
177
178 if self.classifier:
179 Y_pred = Y_pred.argmax(axis=1)
180
181 return Y_pred

Callers 2

plotFunction · 0.95
test_gbdtFunction · 0.95

Calls

no outgoing calls

Tested by 1

test_gbdtFunction · 0.76