Ejemplo n.º 1
0
 def test_save_prediction(self):
     model = RandomForestClassifier()
     model.id = get_model_id(model)
     model.fit(self.iris.data, self.iris.target)
     indexes = np.fromfunction(lambda x: x, (self.iris.data.shape[0], ), dtype=np.int32)
     saving_predict_proba(model, self.iris.data, indexes)
     os.remove('RandomForestClassifier_r0_N__m5_0p0__m4_2__m1_auto__m0_N__m3_1__m2_N__n0_10__b0_1__c1_gini__c0_N_190.csv')
Ejemplo n.º 2
0
 def test_save_prediction(self):
     model = RandomForestClassifier()
     model.id = get_model_id(model)
     model.fit(self.iris.data, self.iris.target)
     indexes = np.fromfunction(lambda x: x, (self.iris.data.shape[0], ), dtype=np.int32)
     saving_predict_proba(model, self.iris.data, indexes)
     os.remove('RandomForestClassifier_r0_N__m5_0p0__m4_2__m1_auto__m0_N__m3_1__m2_N__n0_10__b0_1__c1_gini__c0_N_0_149.csv')
Ejemplo n.º 3
0
 def test_save_prediction(self):
     model = RandomForestClassifier()
     model.id = get_model_id(model)
     model.fit(self.iris.data, self.iris.target)
     indexes = np.fromfunction(lambda x: x, (self.iris.data.shape[0], ), dtype=np.int32)
     saving_predict_proba(model, self.iris.data, indexes)
     any_file_removed = False
     for filename in os.listdir('.'):
         if filename.startswith('RandomForestClassifier'):
             os.remove(filename)
             any_file_removed = True
     self.assertTrue(any_file_removed)
Ejemplo n.º 4
0
 def _get_child_predict(self, clf, X, index=None):
     if self.stack_by_proba and hasattr(clf, 'predict_proba'):
         if self.save_stage0 and index is not None:
             proba = util.saving_predict_proba(clf, X, index)
         else:
             proba = clf.predict_proba(X)
         return proba[:, 1:]
     elif hasattr(clf, 'predict'):
         predict_result = clf.predict(X)
         if isinstance(clf, ClassifierMixin):
             lb = LabelBinarizer()
             lb.fit(predict_result)
             return lb.fit_transform(predict_result)
         else:
             return predict_result.reshape((predict_result.size, 1))
     else:
         return clf.fit_transform(X)
Ejemplo n.º 5
0
 def _get_child_predict(self, clf, X, index=None):
     if self.stack_by_proba and hasattr(clf, 'predict_proba'):
         if self.save_stage0 and index is not None:
             proba = util.saving_predict_proba(clf, X, index)
         else:
             proba = clf.predict_proba(X)
         return proba[:, 1:]
     elif hasattr(clf, 'predict'):
         predict_result = clf.predict(X)
         if isinstance(clf, ClassifierMixin):
             lb = LabelBinarizer()
             lb.fit(predict_result)
             return lb.fit_transform(predict_result)
         else:
             return predict_result.reshape((predict_result.size, 1))
     else:
         return clf.fit_transform(X)
Ejemplo n.º 6
0
    def predict_proba(self, xs_test, index=None):
        """Predict class probabilities for X.

        The predicted class probabilities of an input sample is computed.

        Parameters
        ----------
        X : array-like or sparse matrix of shape = [n_samples, n_features]
            The input samples.

        Returns
        -------
        p : array of shape = [n_samples, n_classes].
            The class probabilities of the input samples.
        """
        return util.saving_predict_proba(self.estimator, xs_test, index,
                                         self.cache_dir)
Ejemplo n.º 7
0
    def predict_proba(self, xs_test, index=None):
        """Predict class probabilities for X.

        The predicted class probabilities of an input sample is computed.

        Parameters
        ----------
        X : array-like or sparse matrix of shape = [n_samples, n_features]
            The input samples.

        Returns
        -------
        p : array of shape = [n_samples, n_classes].
            The class probabilities of the input samples.
        """
        return util.saving_predict_proba(self.estimator,
                                         xs_test,
                                         index,
                                         self.cache_dir)