我有一个使用svc.fit()
进行分类的示例代码,引发了以下查询:
coeff_
和intercept_values
这些值的使用方式,因为我有4个类,所以我得到了一个数组,这些数组具有(6,2)(coeff_)shaped数组考虑到我的输入数据。代码:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import style
from sklearn.svm import SVC
np.set_printoptions(threshold=np.inf)
from sklearn import preprocessing, neighbors
from sklearn.linear_model import LinearRegression
X=np.array([[1,2],[3,4],[5,6],[7,8]])
y = [0,1,2,3]
clf =SVC(kernel='linear',probability = True)
clf.fit(X,y)
print('clf.coef_-----------------',clf.coef_)
print('clf.intercept_-----------------',clf.intercept_)
print('clf.decision_function(X)----------',clf.decision_function(X))
print('clf.decision_function([[2,3]]-',clf.decision_function([[2,3]]))
print('clf.probA_-----------------',clf.probA_)
print('clf.probB_-----------------',clf.probB_)
print("clf.predict_proba([[2,3]].....",clf.predict_proba([[2,3]]))
输出
clf.coef_----------------- [[-0.5 -0.5 ]
[-0.25 -0.25 ]
[-0.16666667 -0.16666667]
[-0.5 -0.5 ]
[-0.25 -0.25 ]
[-0.5 -0.5 ]]
clf.intercept_----------------- [2.5 1.75 1.5 4.5 2.75 6.5 ]
clf.decision_function(X)----------------- [[ 3.1875 2.25
1.0625 -0.5 ]
[ 1.95833333 3.1875 1.125 -0.27083333]
[-0.27083333 2.125 3.1875 0.95833333]
[-0.5 1.0625 2.25 3.1875 ]]
clf.decision_function([[2,3]]----------------- [[ 3.09459459
2.28378378 1.12162162 -0.5 ]]
clf.probA_----------------- [0.69314718 0.69314718 0.69314718
0.69314718 0.69314718 0.69314718]
clf.probB_----------------- [2.39189538e-16 2.39189538e-16
2.39189538e-
16 2.39189538e-16
2.39189538e-16 2.39189538e-16]
clf.predict_proba([[2,3]]..... [[0.22168438 0.14081761 0.12088947
0.51660854]]