コード例 #1
0
ファイル: metafeatures.py プロジェクト: ixtel/auto-sklearn
    def _calculate(self, X, y, categorical):
        import sklearn.lda
        if len(y.shape) == 1 or y.shape[1] == 1:
            kf = sklearn.cross_validation.StratifiedKFold(y, n_folds=10)
        else:
            kf = sklearn.cross_validation.KFold(y.shape[0], n_folds=10)

        accuracy = 0.
        try:
            for train, test in kf:
                lda = sklearn.lda.LDA()

                if len(y.shape) == 1 or y.shape[1] == 1:
                    lda.fit(X[train], y[train])
                else:
                    lda = OneVsRestClassifier(lda)
                    lda.fit(X[train], y[train])

                predictions = lda.predict(X[test])
                accuracy += sklearn.metrics.accuracy_score(predictions, y[test])
            return accuracy / 10
        except scipy.linalg.LinAlgError as e:
            self.logger.warning("LDA failed: %s Returned 0 instead!" % e)
            return np.NaN
        except ValueError as e:
            self.logger.warning("LDA failed: %s Returned 0 instead!" % e)
            return np.NaN
コード例 #2
0
    def _calculate(self, X, y, categorical):
        import sklearn.lda
        if len(y.shape) == 1 or y.shape[1] == 1:
            kf = sklearn.cross_validation.StratifiedKFold(y, n_folds=10)
        else:
            kf = sklearn.cross_validation.KFold(y.shape[0], n_folds=10)

        accuracy = 0.
        try:
            for train, test in kf:
                lda = sklearn.lda.LDA()

                if len(y.shape) == 1 or y.shape[1] == 1:
                    lda.fit(X[train], y[train])
                else:
                    lda = OneVsRestClassifier(lda)
                    lda.fit(X[train], y[train])

                predictions = lda.predict(X[test])
                accuracy += sklearn.metrics.accuracy_score(
                    predictions, y[test])
            return accuracy / 10
        except scipy.linalg.LinAlgError as e:
            self.logger.warning("LDA failed: %s Returned 0 instead!" % e)
            return np.NaN
        except ValueError as e:
            self.logger.warning("LDA failed: %s Returned 0 instead!" % e)
            return np.NaN
コード例 #3
0
 def _calculate(self, X, y, categorical):
     import sklearn.neighbors
     kf = sklearn.cross_validation.StratifiedKFold(y, n_folds=10)
     accuracy = 0.
     for train, test in kf:
         lda = sklearn.neighbors.KNeighborsClassifier(1)
         lda.fit(X[train], y[train])
         predictions = lda.predict(X[test])
         accuracy += sklearn.metrics.accuracy_score(predictions, y[test])
     return accuracy / 10
コード例 #4
0
 def _calculate(self, X, y, categorical):
     import sklearn.lda
     kf = sklearn.cross_validation.StratifiedKFold(y, n_folds=10)
     accuracy = 0.
     try:
         for train, test in kf:
             lda = sklearn.lda.LDA()
             lda.fit(X[train], y[train])
             predictions = lda.predict(X[test])
             accuracy += sklearn.metrics.accuracy_score(predictions, y[test])
         return accuracy / 10
     except scipy.linalg.LinAlgError as e:
         logging.warning("LDA failed: %s Returned 0 instead!" % e)
         return 0
     except ValueError as e:
         logging.warning("LDA failed: %s Returned 0 instead!" % e)
         return 0