简体   繁体   English

svm和logistic回归在python中的准确性差异

[英]accuracy difference between svm and logistic regression in python

I have two classifier in python such as svm and logistic regression. 我在python中有两个分类器,例如svm和logistic回归。

from sklearn import preprocessing
from sklearn.linear_model import LogisticRegression
from sklearn import svm

scaler = preprocessing.StandardScaler()
scaler.fit(synthetic_data)
synthetic_data = scaler.transform(synthetic_data)
test_data = scaler.transform(test_data)

svc = svm.SVC(tol=0.0001, C=100.0).fit(synthetic_data, synthetic_label)
predictedSVM = svc.predict(test_data)
print(accuracy_score(test_label, predictedSVM))

LRmodel = LogisticRegression(penalty='l2', tol=0.0001, C=100.0, random_state=1,max_iter=1000, n_jobs=-1)
predictedLR = LRmodel.fit(synthetic_data, synthetic_label).predict(test_data)
print(accuracy_score(test_label, predictedLR))

I use same input but their accuracy is so different. 我使用相同的输入,但它们的准确性却大不相同。 svm sometimes predicts all predicted svm as 1. Accuracy of svm is 0.45 and accuracy of logistic regression is 0.75. svm有时会将所有预测的svm预测为1。svm的精度为0.45,逻辑回归的精度为0.75。 I changed parameters of C in a different ways, but I have still some problems. 我以不同的方式更改了C的参数,但仍然存在一些问题。

It is because SVC by default uses radial kernel ( http://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html ), which is something different than linear classification. 这是因为SVC默认情况下使用放射状内核( http://scikit-learn.org/stable/modules/generation/sklearn.svm.SVC.html ),这与线性分类有所不同。

If you want to use linear kernel add parameter kernel='linear' to SVC. 如果要使用线性内核,请向SVC添加参数kernel ='linear'。

If you want to keep using radial kernel, I suggest to also change gamma parameter. 如果您想继续使用放射状核,建议您也更改gamma参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 R&python中Logistic回归之间的区别 - Difference between Logistic regression in R & python 在 python 中运行 SVM 和逻辑回归时出错 - Error in running SVM and Logistic Regression in python 如何使用python集成SVM和Logistic回归 - How to ensemble SVM and Logistic Regression with python 为什么该模型在 SVM、随机森林分类器和逻辑回归方面获得 100% 的准确率? - Why is the model getting 100% accuracy for SVM, Random-forest Classifier and Logistic Regression? 如何提高Scikit python中逻辑回归的模型精度? - How to increase the model accuracy of logistic regression in Scikit python? 在Python中使用Logistic回归的预测矢量的准确性得分 - Accuracy Score for a vector of predictions using Logistic Regression in Python Python:逻辑回归 max_iter 参数降低了准确性 - Python: Logistic regression max_iter parameter is reducing the accuracy 如何计算逻辑回归精度 - How to calculate logistic regression accuracy 使用Python,使我的逻辑回归测试精度更接近我的训练准确度 - Making my logistic regression testing accuracy closer to my training accuracy with Python 岭回归和 SVM 回归 (SVR) 之间的差异,多项式 kernel 度数 = 1 - Difference between ridge regression and SVM regressor (SVR) with polynomial kernel of degree = 1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM