简体   繁体   English

如何从Linear SVM手动使用拟合模型进行预测?

[英]How to predict using the fit model from Linear SVM manually?

The scikit.learn function .predict from the library LinearSVC performs the prediction using test samples. 来自LinearSVC库的scikit.learn函数.predict使用测试样本执行预测。

LinearSVM_cl.fit(X_train , Y_train) 

And the prediction with 和预测

Y_pred_LinearSVM = LinearSVM_cl.predict(X_test)  

However, I need to know which parameters from the fit model is used to predict a test samples, .coef_? 但是,我需要知道拟合模型中的哪些参数用于预测测试样本。 .intercept_? 。截距_?

The dataset for the model is 20000 rows and 8 columns obtaining with 8 classes: 该模型的数据集是20000行和8列,其中包含8个类:

.coef -> .coef->

 array([[-1.20185887, -0.62510767, -0.92739275, -0.08900084, -1.11164502,
    -0.56442702,  1.92045989, -0.56706939],
   [ 0.75386897,  0.9672828 , -2.10451063,  0.53552943, -0.10476675,
     0.32058617, -0.30133408, -1.01478727],
   [ 0.35032536, -0.38405342,  0.25462054,  0.47577302, -0.55000734,
     0.01134098, -0.14534849,  1.14597475],
   [-0.08888566, -0.08272116,  0.84141105,  0.22040919,  0.27763948,
     0.57907834, -0.70631803, -0.1017982 ],
   [ 0.14319018,  0.03329494,  1.52575489,  0.58355648,  1.24454465,
    -0.92758526,  1.01315744, -0.51935599],
   [-0.33712774, -0.7826993 , -1.00810522,  0.20346304,  3.67215014,
     0.93187058, -0.26441527, -0.5351838 ],
   [-0.70416157, -2.38388785, -1.24720653,  0.43291862,  3.91473792,
     2.7596399 , -0.63503461, -0.43277051],
   [-0.14921538, -0.03871313, -0.19896247,  0.08522851,  0.29347373,
     0.1332059 , -0.10875692, -0.01503476]])

.intercept -> .intercept->

array([-0.43454897,  0.05659295, -0.95980815, -1.36353241, -3.05042133,
   -2.93684622, -3.35757856, -1.14034588])

And example of test sample is 测试样品的例子是

   0.7622999 0.514543 0.2195486 0.453202 0.2585706 0.6295224 0.4999675 0.1960128

How can I predict the test sample manually (without using the built .predict function from the library). 如何手动预测测试样本(不使用库中内置的.predict函数)。

Note your coef as $W$ and your intercept as $b$ and your new data point as $x$. 注意您的coef为$ W $, intercept为$ b $,新数据点为$ x $。 Your class prediction is simply: 您的课堂预测很简单:

$c = \\arg \\max_i{W_i \\cdot x + b} $ $ c = \\ arg \\ max_i {W_i \\ cdot x + b} $

So you just apply matrix multiplication, add the bias vector and pick the index of the maximal entry. 因此,您只需应用矩阵乘法,添加偏差矢量并选择最大条目的索引。

暂无
暂无

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

相关问题 如何从手动训练的 spacy model 进行预测 - how to predict from manually trained spacy model 使用Python建立线性回归模型并找到R2'd; 无法让模型拟合或预测 - Using Python to build a linear regression model and find R2'd; cannot get the model to fit or predict 如何使用来自 statsmodels 的 linear_model.OLS 使用 LinearRegression 预测数据 - How to predict data using LinearRegression using linear_model.OLS from statsmodels 如何让我的线性回归 model 使用 clf.predict 进行预测? - how do i get my linear regression model to predict using clf.predict? 我如何修复错误:“在训练数据上安装 PCA 转换器并转换数据线”和“model = svm.SVC(kernel='linear')” - How I can fix the error in: "Fit the PCA transformer on the training data and transform the data line" and "model = svm.SVC(kernel='linear')" 使用 SVM 预测概率 - Predict probabilities using SVM 如何在线性回归模型中使用 .predict()? - How to use .predict() in a Linear Regression model? 如何在libsvm中使用svm_model函数'predict'? - How to use the function 'predict' of svm_model in libsvm? 如何对 pandas dataframe 的每一行进行拟合、预测和 plot 线性回归? - How to fit, predict, and plot linear regression for each row of pandas dataframe? 来自 arima 的 model_fit.plot_predict() 和 model_fit.predict() 的结果不同 - different result from model_fit.plot_predict() and model_fit.predict() from arima
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM