本文整理汇总了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