当前位置: 首页>>代码示例>>Python>>正文


Python LinearDiscriminantAnalysis.shStr方法代码示例

本文整理汇总了Python中sklearn.discriminant_analysis.LinearDiscriminantAnalysis.shStr方法的典型用法代码示例。如果您正苦于以下问题:Python LinearDiscriminantAnalysis.shStr方法的具体用法?Python LinearDiscriminantAnalysis.shStr怎么用?Python LinearDiscriminantAnalysis.shStr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sklearn.discriminant_analysis.LinearDiscriminantAnalysis的用法示例。


在下文中一共展示了LinearDiscriminantAnalysis.shStr方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __new__

# 需要导入模块: from sklearn.discriminant_analysis import LinearDiscriminantAnalysis [as 别名]
# 或者: from sklearn.discriminant_analysis.LinearDiscriminantAnalysis import shStr [as 别名]
    def __new__(self, y, clf='lda', kern='rbf', n_knn=10, n_tree=100,
                priors=False, **kwargs):

        # Use a pre-defined classifier :
        if isinstance(clf, (str, int)):
            # Default value for priors :
            priors = np.array([1/len(np.unique(y))]*len(np.unique(y)))

            if isinstance(clf, str):
                clf = clf.lower()

            # LDA :
            if clf == 'lda' or clf == 0:
                clfObj = LinearDiscriminantAnalysis(
                    priors=priors, **kwargs)
                clfObj.lgStr = 'Linear Discriminant Analysis'
                clfObj.shStr = 'LDA'

            # SVM : ‘linear’, ‘poly’, ‘rbf’, ‘sigmoid’, ‘precomputed’ or a callable
            elif clf == 'svm' or clf == 1:
                clfObj = SVC(kernel=kern, probability=True, **kwargs)
                clfObj.lgStr = 'Support Vector Machine (kernel=' + kern + ')'
                clfObj.shStr = 'SVM-' + kern

            # Linear SVM:
            elif clf == 'linearsvm' or clf == 2:
                clfObj = LinearSVC(**kwargs)
                clfObj.lgStr = 'Linear Support Vector Machine'
                clfObj.shStr = 'LSVM'

            # Nu SVM :
            elif clf == 'nusvm' or clf == 3:
                clfObj = NuSVC(**kwargs)
                clfObj.lgStr = 'Nu Support Vector Machine'
                clfObj.shStr = 'NuSVM'

            # Naive Bayesian :
            elif clf == 'nb' or clf == 4:
                clfObj = GaussianNB(**kwargs)
                clfObj.lgStr = 'Naive Baysian'
                clfObj.shStr = 'NB'

            # KNN :
            elif clf == 'knn' or clf == 5:
                clfObj = KNeighborsClassifier(n_neighbors=n_knn, **kwargs)
                clfObj.lgStr = 'k-Nearest Neighbor (neighbor=' + str(n_knn) + ')'
                clfObj.shStr = 'KNN-' + str(n_knn)

            # Random forest :
            elif clf == 'rf' or clf == 6:
                clfObj = RandomForestClassifier(n_estimators=n_tree, **kwargs)
                clfObj.lgStr = 'Random Forest (tree=' + str(n_tree) + ')'
                clfObj.shStr = 'RF-' + str(n_tree)

            # Logistic regression :
            elif clf == 'lr' or clf == 7:
                clfObj = LogisticRegression(**kwargs)
                clfObj.lgStr = 'Logistic Regression'
                clfObj.shStr = 'LogReg'

            # QDA :
            elif clf == 'qda' or clf == 8:
                clfObj = QuadraticDiscriminantAnalysis(**kwargs)
                clfObj.lgStr = 'Quadratic Discriminant Analysis'
                clfObj.shStr = 'QDA'

            else:
                raise ValueError('No classifier "'+str(clf)+'"" found')

        # Use a custom classifier :
        else:
            clfObj = clf
            clfObj.shStr = 'custom'
            clfObj.lgStr = 'Custom classifier'


        return clfObj
开发者ID:EtienneCmb,项目名称:brainpipe,代码行数:79,代码来源:_classif.py


注:本文中的sklearn.discriminant_analysis.LinearDiscriminantAnalysis.shStr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。