classification - Python - Predict using the fit model from Linear SVM manually -


the scikit.learn function .predict library linearsvc performs prediction using test samples.

linearsvm_cl.fit(x_train , y_train)  

and prediction

y_pred_linearsvm = linearsvm_cl.predict(x_test)   

however, need know parameters fit model used predict test samples, .coef_? .intercept_?

the dataset model 20000 rows , 8 columns obtaining 8 classes:

.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 ->

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

and example of test sample

   0.7622999 0.514543 0.2195486 0.453202 0.2585706 0.6295224 0.4999675 0.1960128 

how can predict test sample manually (without using built .predict function library).

note coef $w$ , intercept $b$ , new data point $x$. class prediction simply:

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

so apply matrix multiplication, add bias vector , pick index of maximal entry.


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -