[英]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.