本文整理匯總了Python中sklearn.discriminant_analysis.QuadraticDiscriminantAnalysis方法的典型用法代碼示例。如果您正苦於以下問題:Python discriminant_analysis.QuadraticDiscriminantAnalysis方法的具體用法?Python discriminant_analysis.QuadraticDiscriminantAnalysis怎麽用?Python discriminant_analysis.QuadraticDiscriminantAnalysis使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sklearn.discriminant_analysis
的用法示例。
在下文中一共展示了discriminant_analysis.QuadraticDiscriminantAnalysis方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_qda
# 需要導入模塊: from sklearn import discriminant_analysis [as 別名]
# 或者: from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis [as 別名]
def test_qda():
# QDA classification.
# This checks that QDA implements fit and predict and returns
# correct values for a simple toy dataset.
clf = QuadraticDiscriminantAnalysis()
y_pred = clf.fit(X6, y6).predict(X6)
assert_array_equal(y_pred, y6)
# Assure that it works with 1D data
y_pred1 = clf.fit(X7, y6).predict(X7)
assert_array_equal(y_pred1, y6)
# Test probas estimates
y_proba_pred1 = clf.predict_proba(X7)
assert_array_equal((y_proba_pred1[:, 1] > 0.5) + 1, y6)
y_log_proba_pred1 = clf.predict_log_proba(X7)
assert_array_almost_equal(np.exp(y_log_proba_pred1), y_proba_pred1, 8)
y_pred3 = clf.fit(X6, y7).predict(X6)
# QDA shouldn't be able to separate those
assert np.any(y_pred3 != y7)
# Classes should have at least 2 elements
assert_raises(ValueError, clf.fit, X6, y4)
示例2: test_qda_store_covariance
# 需要導入模塊: from sklearn import discriminant_analysis [as 別名]
# 或者: from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis [as 別名]
def test_qda_store_covariance():
# The default is to not set the covariances_ attribute
clf = QuadraticDiscriminantAnalysis().fit(X6, y6)
assert not hasattr(clf, 'covariance_')
# Test the actual attribute:
clf = QuadraticDiscriminantAnalysis(store_covariance=True).fit(X6, y6)
assert hasattr(clf, 'covariance_')
assert_array_almost_equal(
clf.covariance_[0],
np.array([[0.7, 0.45], [0.45, 0.7]])
)
assert_array_almost_equal(
clf.covariance_[1],
np.array([[0.33333333, -0.33333333], [-0.33333333, 0.66666667]])
)
示例3: test_qda_regularization
# 需要導入模塊: from sklearn import discriminant_analysis [as 別名]
# 或者: from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis [as 別名]
def test_qda_regularization():
# the default is reg_param=0. and will cause issues
# when there is a constant variable
clf = QuadraticDiscriminantAnalysis()
with ignore_warnings():
y_pred = clf.fit(X2, y6).predict(X2)
assert np.any(y_pred != y6)
# adding a little regularization fixes the problem
clf = QuadraticDiscriminantAnalysis(reg_param=0.01)
with ignore_warnings():
clf.fit(X2, y6)
y_pred = clf.predict(X2)
assert_array_equal(y_pred, y6)
# Case n_samples_in_a_class < n_features
clf = QuadraticDiscriminantAnalysis(reg_param=0.1)
with ignore_warnings():
clf.fit(X5, y5)
y_pred5 = clf.predict(X5)
assert_array_equal(y_pred5, y5)
示例4: __init__
# 需要導入模塊: from sklearn import discriminant_analysis [as 別名]
# 或者: from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis [as 別名]
def __init__(self, classifier=FaceClassifierModels.DEFAULT):
self._clf = None
if classifier == FaceClassifierModels.LINEAR_SVM:
self._clf = SVC(C=1.0, kernel="linear", probability=True)
elif classifier == FaceClassifierModels.NAIVE_BAYES:
self._clf = GaussianNB()
elif classifier == FaceClassifierModels.RBF_SVM:
self._clf = SVC(C=1, kernel='rbf', probability=True, gamma=2)
elif classifier == FaceClassifierModels.NEAREST_NEIGHBORS:
self._clf = KNeighborsClassifier(1)
elif classifier == FaceClassifierModels.DECISION_TREE:
self._clf = DecisionTreeClassifier(max_depth=5)
elif classifier == FaceClassifierModels.RANDOM_FOREST:
self._clf = RandomForestClassifier(max_depth=5, n_estimators=10, max_features=1)
elif classifier == FaceClassifierModels.NEURAL_NET:
self._clf = MLPClassifier(alpha=1)
elif classifier == FaceClassifierModels.ADABOOST:
self._clf = AdaBoostClassifier()
elif classifier == FaceClassifierModels.QDA:
self._clf = QuadraticDiscriminantAnalysis()
print("classifier={}".format(FaceClassifierModels(classifier)))
示例5: getModels
# 需要導入模塊: from sklearn import discriminant_analysis [as 別名]
# 或者: from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis [as 別名]
def getModels():
result = []
result.append("LinearRegression")
result.append("BayesianRidge")
result.append("ARDRegression")
result.append("ElasticNet")
result.append("HuberRegressor")
result.append("Lasso")
result.append("LassoLars")
result.append("Rigid")
result.append("SGDRegressor")
result.append("SVR")
result.append("MLPClassifier")
result.append("KNeighborsClassifier")
result.append("SVC")
result.append("GaussianProcessClassifier")
result.append("DecisionTreeClassifier")
result.append("RandomForestClassifier")
result.append("AdaBoostClassifier")
result.append("GaussianNB")
result.append("LogisticRegression")
result.append("QuadraticDiscriminantAnalysis")
return result
示例6: main
# 需要導入模塊: from sklearn import discriminant_analysis [as 別名]
# 或者: from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis [as 別名]
def main():
# prepare data
trainingSet=[]
testSet=[]
accuracy = 0.0
split = 0.25
loadDataset('../Dataset/combined.csv', split, trainingSet, testSet)
print 'Train set: ' + repr(len(trainingSet))
print 'Test set: ' + repr(len(testSet))
# generate predictions
predictions=[]
trainData = np.array(trainingSet)[:,0:np.array(trainingSet).shape[1] - 1]
columns = trainData.shape[1]
X = np.array(trainData)
y = np.array(trainingSet)[:,columns]
clf = BaggingClassifier(QDA())
clf.fit(X, y)
testData = np.array(testSet)[:,0:np.array(trainingSet).shape[1] - 1]
X_test = np.array(testData)
y_test = np.array(testSet)[:,columns]
accuracy = clf.score(X_test,y_test)
accuracy *= 100
print("Accuracy %:",accuracy)
示例7: test_qda
# 需要導入模塊: from sklearn import discriminant_analysis [as 別名]
# 或者: from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis [as 別名]
def test_qda():
# QDA classification.
# This checks that QDA implements fit and predict and returns
# correct values for a simple toy dataset.
clf = QuadraticDiscriminantAnalysis()
y_pred = clf.fit(X6, y6).predict(X6)
assert_array_equal(y_pred, y6)
# Assure that it works with 1D data
y_pred1 = clf.fit(X7, y6).predict(X7)
assert_array_equal(y_pred1, y6)
# Test probas estimates
y_proba_pred1 = clf.predict_proba(X7)
assert_array_equal((y_proba_pred1[:, 1] > 0.5) + 1, y6)
y_log_proba_pred1 = clf.predict_log_proba(X7)
assert_array_almost_equal(np.exp(y_log_proba_pred1), y_proba_pred1, 8)
y_pred3 = clf.fit(X6, y7).predict(X6)
# QDA shouldn't be able to separate those
assert_true(np.any(y_pred3 != y7))
# Classes should have at least 2 elements
assert_raises(ValueError, clf.fit, X6, y4)
示例8: test_qda_store_covariance
# 需要導入模塊: from sklearn import discriminant_analysis [as 別名]
# 或者: from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis [as 別名]
def test_qda_store_covariance():
# The default is to not set the covariances_ attribute
clf = QuadraticDiscriminantAnalysis().fit(X6, y6)
assert_false(hasattr(clf, 'covariance_'))
# Test the actual attribute:
clf = QuadraticDiscriminantAnalysis(store_covariance=True).fit(X6, y6)
assert_true(hasattr(clf, 'covariance_'))
assert_array_almost_equal(
clf.covariance_[0],
np.array([[0.7, 0.45], [0.45, 0.7]])
)
assert_array_almost_equal(
clf.covariance_[1],
np.array([[0.33333333, -0.33333333], [-0.33333333, 0.66666667]])
)
示例9: test_qda_regularization
# 需要導入模塊: from sklearn import discriminant_analysis [as 別名]
# 或者: from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis [as 別名]
def test_qda_regularization():
# the default is reg_param=0. and will cause issues
# when there is a constant variable
clf = QuadraticDiscriminantAnalysis()
with ignore_warnings():
y_pred = clf.fit(X2, y6).predict(X2)
assert_true(np.any(y_pred != y6))
# adding a little regularization fixes the problem
clf = QuadraticDiscriminantAnalysis(reg_param=0.01)
with ignore_warnings():
clf.fit(X2, y6)
y_pred = clf.predict(X2)
assert_array_equal(y_pred, y6)
# Case n_samples_in_a_class < n_features
clf = QuadraticDiscriminantAnalysis(reg_param=0.1)
with ignore_warnings():
clf.fit(X5, y5)
y_pred5 = clf.predict(X5)
assert_array_equal(y_pred5, y5)
示例10: test_qda_priors
# 需要導入模塊: from sklearn import discriminant_analysis [as 別名]
# 或者: from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis [as 別名]
def test_qda_priors():
clf = QuadraticDiscriminantAnalysis()
y_pred = clf.fit(X6, y6).predict(X6)
n_pos = np.sum(y_pred == 2)
neg = 1e-10
clf = QuadraticDiscriminantAnalysis(priors=np.array([neg, 1 - neg]))
y_pred = clf.fit(X6, y6).predict(X6)
n_pos2 = np.sum(y_pred == 2)
assert_greater(n_pos2, n_pos)
示例11: __init__
# 需要導入模塊: from sklearn import discriminant_analysis [as 別名]
# 或者: from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis [as 別名]
def __init__(self, priors=None, reg_param=0.0, store_covariance=False, tol=0.0001, store_covariances=None):
self._hyperparams = {
'priors': priors,
'reg_param': reg_param,
'store_covariance': store_covariance,
'tol': tol,
'store_covariances': store_covariances}
self._wrapped_model = Op(**self._hyperparams)
示例12: __init__
# 需要導入模塊: from sklearn import discriminant_analysis [as 別名]
# 或者: from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis [as 別名]
def __init__(self, **kwargs):
super(QuadraticLDA, self).__init__()
self.clf = _QuadraticDiscriminantAnalysis(**kwargs)
示例13: test_objectmapper
# 需要導入模塊: from sklearn import discriminant_analysis [as 別名]
# 或者: from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis [as 別名]
def test_objectmapper(self):
df = pdml.ModelFrame([])
self.assertIs(df.discriminant_analysis.LinearDiscriminantAnalysis,
da.LinearDiscriminantAnalysis)
self.assertIs(df.discriminant_analysis.QuadraticDiscriminantAnalysis,
da.QuadraticDiscriminantAnalysis)
self.assertIs(df.da.LinearDiscriminantAnalysis,
da.LinearDiscriminantAnalysis)
self.assertIs(df.da.QuadraticDiscriminantAnalysis,
da.QuadraticDiscriminantAnalysis)
示例14: test_objectmapper_deprecated
# 需要導入模塊: from sklearn import discriminant_analysis [as 別名]
# 或者: from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis [as 別名]
def test_objectmapper_deprecated(self):
df = pdml.ModelFrame([])
with tm.assert_produces_warning(FutureWarning):
self.assertIs(df.lda.LinearDiscriminantAnalysis,
da.LinearDiscriminantAnalysis)
with tm.assert_produces_warning(FutureWarning):
self.assertIs(df.qda.QuadraticDiscriminantAnalysis,
da.QuadraticDiscriminantAnalysis)
示例15: test_qda_deprecation
# 需要導入模塊: from sklearn import discriminant_analysis [as 別名]
# 或者: from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis [as 別名]
def test_qda_deprecation():
# Test the deprecation
clf = QuadraticDiscriminantAnalysis(store_covariances=True)
assert_warns_message(DeprecationWarning, "'store_covariances' was renamed"
" to store_covariance in version 0.19 and will be "
"removed in 0.21.", clf.fit, X, y)
# check that covariance_ (and covariances_ with warning) is stored
assert_warns_message(DeprecationWarning, "Attribute covariances_ was "
"deprecated in version 0.19 and will be removed "
"in 0.21. Use covariance_ instead", getattr, clf,
'covariances_')