本文整理汇总了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
示例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
示例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))
示例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]
示例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)
示例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)
示例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 ''
示例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: