【达观杯】数据竞赛学习篇(四)LR & SVM

Support Vector Machine (SVM) is an algorithm used for classification problems similar to Logistic Regression (LR). LR and SVM with linear Kernel generally perform comparably in practice.

LogisticRegression sklearn

SVM sklearn

如果Feature的数量很大,跟样本数量差不多,这时候选用LR或者是Linear Kernel的SVM2. 如果Feature的数量比较小,样本数量一般,不算大也不算小,选用SVM+Gaussian Kernel3. 如果Feature的数量比较小,而样本数量很多,需要手工添加一些feature变成第一种情况

代码实现:


from sklearn.linear_model import LogisticRegression
from sklearn import svm
from sklearn.metrics import f1_score

clf = LogisticRegression(C=120, dual=True)
#clf = svm.LinearSVC(C=5, dual=False)

clf.fit(X_train, y_train)
y_prediction = clf.predict(X_test)
f1 = f1_score(y_test, y_prediction, average='micro')
print('The F1 Score: ' + str("%.2f" % f1))

猜你喜欢

转载自blog.csdn.net/weixin_42317507/article/details/89220707