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


Python NuSVC.score方法代碼示例

本文整理匯總了Python中sklearn.svm.NuSVC.score方法的典型用法代碼示例。如果您正苦於以下問題:Python NuSVC.score方法的具體用法?Python NuSVC.score怎麽用?Python NuSVC.score使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sklearn.svm.NuSVC的用法示例。


在下文中一共展示了NuSVC.score方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: sigmoidNuSVC

# 需要導入模塊: from sklearn.svm import NuSVC [as 別名]
# 或者: from sklearn.svm.NuSVC import score [as 別名]
def sigmoidNuSVC():
    maxRandomPerformance = []
    for gamma in xrange(1,200):
        clf = NuSVC(kernel="sigmoid",gamma=gamma)
        clf.fit(trainData, trainLabel)
        maxRandomPerformance.append(clf.score(validationData, validationLabel))

    gammaValue = maxRandomPerformance.index(max(maxRandomPerformance)) + 1
    clfFinal = NuSVC(kernel='sigmoid', gamma=gammaValue)
    clfFinal.fit(trainData,trainLabel)
    score = clfFinal.score(testData,testLabel)

    guideToGraph['Sigmoid Nu-SVC'] = score
開發者ID:RonakSumbaly,項目名稱:Malware-Classification,代碼行數:15,代碼來源:classifications.py

示例2: polyNuSVC

# 需要導入模塊: from sklearn.svm import NuSVC [as 別名]
# 或者: from sklearn.svm.NuSVC import score [as 別名]
def polyNuSVC():
    maxRandomPerformance = []

    for deg in xrange(1,200):
        clf = NuSVC(kernel="poly",degree=deg)
        clf.fit(trainData, trainLabel)
        maxRandomPerformance.append(clf.score(validationData, validationLabel))

    gammaValue = maxRandomPerformance.index(max(maxRandomPerformance)) + 1
    clfFinal = NuSVC(kernel='poly', gamma=gammaValue)
    clfFinal.fit(trainData,trainLabel)
    score = clfFinal.score(testData,testLabel)

    guideToGraph['Polynomial Nu-SVC'] = score
開發者ID:RonakSumbaly,項目名稱:Malware-Classification,代碼行數:16,代碼來源:classifications.py

示例3: svmClassifier

# 需要導入模塊: from sklearn.svm import NuSVC [as 別名]
# 或者: from sklearn.svm.NuSVC import score [as 別名]
def svmClassifier():
    for deg in xrange(1,200):
        print deg
        print "RBF Nu-SVC"
        clf = NuSVC(gamma=deg)
        clf.fit(trainData, trainLabel)
        print(clf.score(testData,testLabel))

        print "LINEAR Nu-SVC"
        clf = NuSVC(kernel="linear")
        clf.fit(trainData, trainLabel)
        print(clf.score(testData,testLabel))

        print "POLYNOMIAL Nu-SVC"
        clf = NuSVC(kernel="poly",gamma=deg)
        clf.fit(trainData, trainLabel)
        print(clf.score(testData,testLabel))

        print "SIGMOID Nu-SVC"
        clf = NuSVC(kernel="sigmoid",gamma=deg)
        clf.fit(trainData, trainLabel)
        print(clf.score(testData,testLabel))
開發者ID:RonakSumbaly,項目名稱:CS260-Machine-Learning-Algorithms,代碼行數:24,代碼來源:svmClassifier.py

示例4: runClassifier

# 需要導入模塊: from sklearn.svm import NuSVC [as 別名]
# 或者: from sklearn.svm.NuSVC import score [as 別名]
def runClassifier(classifier, trainData,trainLabel, testData, testLabel, bestParameters):
    if classifier[0] == 'KNN':
        neighTest = KNeighborsClassifier(n_neighbors=int(bestParameters['KNN'][0]), algorithm='auto', p=2,weights=bestParameters['KNN'][1])
        neighTest.fit(trainData, trainLabel)
        scoreTest = neighTest.score(testData, testLabel)
        return scoreTest - classifier[1]
    elif classifier[0] == 'Random Forests':
        neighTest = RandomForestClassifier(n_estimators = int(bestParameters['Random Forests'][0]),criterion=bestParameters['Random Forests'][1])
        neighTest.fit(trainData, trainLabel)
        scoreTest = neighTest.score(testData, testLabel)
        return scoreTest - classifier[1]
    elif classifier[0] == 'Linear Nu-SVC':
        clf = NuSVC(kernel="linear")
        clf.fit(trainData, trainLabel)
        scoreTest = clf.score(testData, testLabel)
        return scoreTest - classifier[1]
    elif classifier[0] == 'RBF Nu-SVC':
        clfFinal = NuSVC(gamma = bestParameters['RBF Nu-SVC'])
        clfFinal.fit(trainData,trainLabel)
        score = clfFinal.score(testData,testLabel)
        return score - classifier[1]
    elif classifier[0] == 'Gradient Boosting':
        neighTest = GradientBoostingClassifier(n_estimators = int(bestParameters['Gradient Boosting'][0]),loss='deviance')
        neighTest.fit(trainData, trainLabel)
        scoreTest = neighTest.score(testData, testLabel)
        return scoreTest - classifier[1]
    elif classifier[0] == 'Multinomial Naive Bayes':
        clfTest = MultinomialNB(alpha = bestParameters['Multinomial Naive Bayes'], fit_prior=True)
        clfTest.fit(trainData, trainLabel)
        scoreTest = clfTest.score(testData, testLabel)
        return scoreTest - classifier[1]
    elif classifier[0] == 'Decision (IG)':
        clf = tree.DecisionTreeClassifier(criterion='entropy')
        clf.fit(trainData, trainLabel)
        scoreTest = clf.score(testData, testLabel)
        return scoreTest - classifier[1]
開發者ID:RonakSumbaly,項目名稱:CS260-Machine-Learning-Algorithms,代碼行數:38,代碼來源:bestFeature.py

示例5: NuSVC

# 需要導入模塊: from sklearn.svm import NuSVC [as 別名]
# 或者: from sklearn.svm.NuSVC import score [as 別名]
svc_new.fit(train_x_reduced, train_y_practice)
print svc_new.score(test_x_reduced, test_y_practice)
"""
"""
parameters = {'degree':(1, 3, 6)}
svclass = NuSVC(kernel='poly', probability=True, gamma=0, nu=.5852, tol=.00001)
clf = GridSearchCV(svclass, parameters, cv=10)
clf.fit(train_x_reduced, train_y_practice)
print "SVC"
print clf.best_estimator_
print clf.best_score_
print clf.best_params_
"""
svc_new = NuSVC(kernel='poly', probability=True, gamma=0, nu=.5852, tol=.00001)
svc_new.fit(train_x_reduced, train_y_practice)
print svc_new.score(test_x_reduced, test_y_practice)


print 'Predicting'
estimator = SelectKBest(score_func=f_classif, k=components)
estimator.fit(train_x, train_y_leaderboard)
train_x_reduced = estimator.transform(train_x)
test_x_reduced = estimator.transform(test_x)
print train_x.shape
print train_x_reduced.shape

#svc_new = SVC(probability=True, C=.000001, kernel='poly', gamma=4,
#                  degree=4)
svc_new = NuSVC(kernel='poly', probability=True, gamma=0, nu=.5852, tol=.00001)
svc_new.fit(train_x_reduced, train_y_leaderboard)
output = svc_new.predict(test_x_reduced)
開發者ID:rdimaggio,項目名稱:kaggle_overfitting,代碼行數:33,代碼來源:analysis_v1.py

示例6: linearNuSVC

# 需要導入模塊: from sklearn.svm import NuSVC [as 別名]
# 或者: from sklearn.svm.NuSVC import score [as 別名]
def linearNuSVC():
    clf = NuSVC(kernel="linear")
    clf.fit(trainData, trainLabel)
    guideToGraph['Linear Nu-SVC'] = clf.score(validationData, validationLabel)
開發者ID:RonakSumbaly,項目名稱:Malware-Classification,代碼行數:6,代碼來源:classifications.py

示例7: NuSVC

# 需要導入模塊: from sklearn.svm import NuSVC [as 別名]
# 或者: from sklearn.svm.NuSVC import score [as 別名]
)
print "Cross-domain error for kitchen-electronics (trained PCA kitchen data to predict test PCA electroincs data)", kitchenSVC.score(
    electronics_test_matrix.todense(), test_label
)
print "In-domain error for kitchen-kitchen (trained PCA kitchen data to predict test PCA kitchen data)", kitchenSVC.score(
    kitchen_test_matrix.todense(), test_label
)


print "----PCA + NON-linear SVM"

# NuSVC results book->all
book_clf = NuSVC()
book_clf.fit(book_train_new_fit, train_label)
print "In-domain error for book-book (trained PCA book data to predict test PCA book data)", book_clf.score(
    book_test_new_fit, test_label
)
print "Cross-domain error for book-DVD (trained PCA book data to predict test PCA DVD data)", book_clf.score(
    DVD_test_new_fit, test_label
)
print "Cross-domain error for book-electronics (trained PCA book data to predict test PCA electroincs data)", book_clf.score(
    electronics_test_new_fit, test_label
)
print "Cross-domain error for book-kitchen (trained PCA book data to predict test PCA kitchen data)", book_clf.score(
    kitchen_test_new_fit, test_label
)

# NuSVC results DVD->all
DVD_clf = NuSVC()
DVD_clf.fit(DVD_train_new_fit, train_label)
print "Cross-domain error for DVD-book (trained PCA DVD data to predict test PCA book data) ", DVD_clf.score(
開發者ID:ChanningPing,項目名稱:cross-domain-sentiment-classification,代碼行數:33,代碼來源:qp27_CS+613+final+project.py

示例8: LinearSVR

# 需要導入模塊: from sklearn.svm import NuSVC [as 別名]
# 或者: from sklearn.svm.NuSVC import score [as 別名]
lsvr = LinearSVR()
print 'LinearSVR config:'
print svc.get_params()
lsvr.fit(smr_train.feature_matrix, smr_train.labels)
lsvr_score_train = svc.score(smr_train.feature_matrix, smr_train.labels)
print 'LinearSVR precision train: {}'.format(lsvr_score_train)
lsvr_score_test = lsvr.score(smr_test.feature_matrix, smr_test.labels)
print 'LinearSVR precision test: {}'.format(lsvr_score_test)
print ''

nusvc = NuSVC()
print 'NuSVC config:'
print nusvc.get_params()
nusvc.fit(smr_train.feature_matrix, smr_train.labels)
nusvc_score_train = nusvc.score(smr_train.feature_matrix, smr_train.labels)
print 'NuSVC precision train: {}'.format(nusvc_score_train)
nusvc_score_test = nusvc.score(smr_test.feature_matrix, smr_test.labels)
print 'NuSVC precision test: {}'.format(nusvc_score_test)
print ''

nusvr = NuSVR()
print 'NuSVR config:'
print nusvr.get_params()
nusvr.fit(smr_train.feature_matrix, smr_train.labels)
nusvr_score_train = svc.score(smr_train.feature_matrix, smr_train.labels)
print 'NuSVR precision train: {}'.format(nusvr_score_train)
nusvr_score_test = nusvr.score(smr_test.feature_matrix, smr_test.labels)
print 'NuSVR precision test: {}'.format(nusvr_score_test)
print ''
開發者ID:heroxdream,項目名稱:information-retrieval,代碼行數:31,代碼來源:models.py

示例9: print

# 需要導入模塊: from sklearn.svm import NuSVC [as 別名]
# 或者: from sklearn.svm.NuSVC import score [as 別名]
SVC_classifier.fit(train_arrays, train_labels)
print('SVC Accuracy: %.2f' %SVC_classifier.score(test_arrays, test_labels))

LinearSVC_classifier = LinearSVC(multi_class='ovr')
LinearSVC_classifier.fit(train_arrays, train_labels)
print('LinearSVC Accuracy: %.2f' %LinearSVC_classifier.score(test_arrays, test_labels))

SGD_classifier = SGDClassifier()
SGD_classifier.fit(train_arrays, train_labels)
print('SGDClassifier Accuracy: %.2f' %SGD_classifier.score(test_arrays, test_labels))


try:
    NuSVC_classifier = NuSVC()
    NuSVC_classifier.fit(train_arrays, train_labels)
    print('NuSVC Accuracy: %.2f' %NuSVC_classifier.score(test_arrays, test_labels))
except:
    pass

try:
    MultinomialNB_classifier = MultinomialNB()
    MultinomialNB_classifier.fit(train_arrays, train_labels)
    print('MultinomialNB Accuracy: %.2f' %MultinomialNB_classifier.score(test_arrays, test_labels))
except:
    pass

try:
    BernoulliNB_classifier = BernoulliNB()
    BernoulliNB_classifier.fit(train_arrays, train_labels)
    print('BernoulliNB Accuracy: %.2f' %BernoulliNB_classifier.score(test_arrays, test_labels))
except:
開發者ID:Vahidsj,項目名稱:first-repo,代碼行數:33,代碼來源:Training+Doc2Vec+and+Classifier+-+Positive-Negative.py


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