當前位置: 首頁>>代碼示例>>Python>>正文


Python discriminant_analysis.QuadraticDiscriminantAnalysis方法代碼示例

本文整理匯總了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) 
開發者ID:PacktPublishing,項目名稱:Mastering-Elasticsearch-7.0,代碼行數:26,代碼來源:test_discriminant_analysis.py

示例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]])
    ) 
開發者ID:PacktPublishing,項目名稱:Mastering-Elasticsearch-7.0,代碼行數:20,代碼來源:test_discriminant_analysis.py

示例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) 
開發者ID:PacktPublishing,項目名稱:Mastering-Elasticsearch-7.0,代碼行數:23,代碼來源:test_discriminant_analysis.py

示例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))) 
開發者ID:richmondu,項目名稱:libfaceid,代碼行數:23,代碼來源:classifier.py

示例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 
開發者ID:tech-quantum,項目名稱:sia-cog,代碼行數:25,代碼來源:scikitlearn.py

示例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) 
開發者ID:DedSecInside,項目名稱:Awesome-Scripts,代碼行數:25,代碼來源:BaggedQDA.py

示例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) 
開發者ID:alvarobartt,項目名稱:twitter-stock-recommendation,代碼行數:26,代碼來源:test_discriminant_analysis.py

示例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]])
    ) 
開發者ID:alvarobartt,項目名稱:twitter-stock-recommendation,代碼行數:20,代碼來源:test_discriminant_analysis.py

示例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) 
開發者ID:alvarobartt,項目名稱:twitter-stock-recommendation,代碼行數:23,代碼來源:test_discriminant_analysis.py

示例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) 
開發者ID:PacktPublishing,項目名稱:Mastering-Elasticsearch-7.0,代碼行數:13,代碼來源:test_discriminant_analysis.py

示例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) 
開發者ID:IBM,項目名稱:lale,代碼行數:10,代碼來源:quadratic_discriminant_analysis.py

示例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) 
開發者ID:gumpy-bci,項目名稱:gumpy,代碼行數:5,代碼來源:common.py

示例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) 
開發者ID:pandas-ml,項目名稱:pandas-ml,代碼行數:13,代碼來源:test_discriminant_analysis.py

示例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) 
開發者ID:pandas-ml,項目名稱:pandas-ml,代碼行數:10,代碼來源:test_discriminant_analysis.py

示例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_') 
開發者ID:alvarobartt,項目名稱:twitter-stock-recommendation,代碼行數:14,代碼來源:test_discriminant_analysis.py


注:本文中的sklearn.discriminant_analysis.QuadraticDiscriminantAnalysis方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。