def predict(self, X): """ Predict best arm for new data. Note ---- While in theory, making predictions from this algorithm should be faster than from others, the implementation here uses a Python loop for each observation, which is slow compared to NumPy array lookups, so the predictions will be slower to calculate than those from other algorithms. Parameters ---------- X : array (n_samples, n_features) New observations for which to choose an action. Returns ------- pred : array (n_samples,) Actions chosen by this technique. """ X = _check_X_input(X) pred = np.zeros(X.shape[0]) shape_single = list(X.shape) shape_single[0] = 1 Parallel(n_jobs=self.njobs, verbose=0, require="sharedmem")(delayed(self._predict)(pred, i, shape_single, X) for i in range(X.shape[0])) return np.array(pred).astype('int64')
def predict(self, X): """ Predict best arm for new data. Note ---- While in theory, making predictions from this algorithm should be faster than from others, the implementation here uses a Python loop for each observation, which is slow compared to NumPy array lookups, so the predictions will be slower to calculate than those from other algorithms. Parameters ---------- X : array (n_samples, n_features) New observations for which to choose an action. Returns ------- pred : array (n_samples,) Actions chosen by this technique. """ X = _check_X_input(X) out = list() for i in range(X.shape[0]): out.append(self._predict(X[i, :].reshape(1, -1))) return np.array(out)
def _check_inputs(self, X, y, sample_weight): X = _check_X_input(X) y = _check_1d_inp(y) assert X.shape[0] == y.shape[0] if sample_weight is None: sample_weight = np.ones(X.shape[0]) assert sample_weight.shape[0] == X.shape[0] sample_weight /= sample_weight.sum() return X, y, sample_weight
def predict(self, X): """ Predict best arm for new data. Parameters ---------- X : array (n_samples, n_features) New observations for which to choose an action. Returns ------- pred : array (n_samples,) Actions chosen by this technique. """ X = _check_X_input(X) return self.oracle.predict(X)
def decision_function(self, X): """ Decision function before sigmoid transformation for new observations Parameters ---------- X : array(n_samples, n_features) Input data on which to predict. Returns ------- pred : array(n_samples, ) Raw prediction for each observation """ X = _check_X_input(X) if self.fit_intercept: return X.dot(self.w[:self.w.shape[0] - 1]) + self.w[-1] else: return X.dot(self.w)
def decision_function(self, X): """ Get score distribution for the arm's rewards Note ---- For details on how this is calculated, see the documentation of the RegressionOneVsRest and WeightedAllPairs classes in the costsensitive package. Parameters ---------- X : array (n_samples, n_features) New observations for which to evaluate actions. Returns ------- pred : array (n_samples, n_choices) Score assigned to each arm for each observation (see Note). """ X = _check_X_input(X) return self.oracle.decision_function(X)