【问题标题】:SVC with linear kernal accuracy is 51%具有线性核精度的 SVC 为 51%
【发布时间】:2023-01-05 13:34:33
【问题描述】:
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=0)

Linear_SVC_classifier = SVC(kernel='linear', random_state=1)#supervised learning
Linear_SVC_classifier.fit(x_train, y_train)
SVC_Accuracy = accuracy_score(y_test, SVC_Prediction)
print("\n\n\nLinear SVM Accuracy: ", SVC_Accuracy)

我在训练时尝试使用 random_state=42,但模型的性能没有提高。数据集是平衡的,有 40,000 条二进制分类 (0,1) 的记录。

【问题讨论】:

  • 如何提高线性 SVC 的性能?
  • 您可以查看您的数据(清理、特征选择/工程),然后进行超参数调整。如果您没有受困于 SVC,您也可以尝试不同的模型。网上可能有很多文章解释了帮助提高绩效的不同方法
  • 数据已清理,我应用 tf-idf 进行特征选择
  • 尝试更改内核。基本上是超参数调整。您可以做一些 EDA 来了解哪些超参数/模型可能适合数据并从那里开始。
  • 我只能使用线性 SVM 模型,这就是我不能更改内核的原因。如果您知道任何其他解决方案,请建议我。

标签: python machine-learning svc


【解决方案1】:

将计数向量化器添加到您的训练数据并使用逻辑回归模型

from sklearn.model_selection import train_test_split
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score 

X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0) 

cv = CountVectorizer() 
ctmTr = cv.fit_transform(X_train) 
X_test_dtm = cv.transform(X_test)

model = LogisticRegression() 
model.fit(ctmTr, y_train)

y_pred_class = model.predict(X_test_dtm)

SVC_Accuracy = accuracy_score(y_test)
print("


Linear SVM Accuracy: ", SVC_Accuracy)

上面的模型定义是'相等的' 对这个声明

Linear_SVC_classifier = SVC(kernel='linear', random_state=1)  
Linear_SVC_classifier.fit(ctmTr, y_train)

【讨论】:

    猜你喜欢
    • 2019-02-12
    • 2020-11-07
    • 2021-11-02
    • 1970-01-01
    • 2016-01-31
    • 2014-07-06
    • 2017-09-06
    • 1970-01-01
    • 2012-09-28
    相关资源
    最近更新 更多