MCPcopy
hub / github.com/apachecn/ailearning / kernelTrans

Function kernelTrans

src/python/6.SVM/svm-complete.py:50–74  ·  view source on GitHub ↗

核转换函数 Args: X dataMatIn数据集 A dataMatIn数据集的第i行的数据 kTup 核函数的信息 Returns:

(X, A, kTup)

Source from the content-addressed store, hash-verified

48
49
50def kernelTrans(X, A, kTup): # calc the kernel or transform data to a higher dimensional space
51 """
52 核转换函数
53 Args:
54 X dataMatIn数据集
55 A dataMatIn数据集的第i行的数据
56 kTup 核函数的信息
57
58 Returns:
59
60 """
61 m, n = shape(X)
62 K = mat(zeros((m, 1)))
63 if kTup[0] == 'lin':
64 # linear kernel: m*n * n*1 = m*1
65 K = X * A.T
66 elif kTup[0] == 'rbf':
67 for j in range(m):
68 deltaRow = X[j, :] - A
69 K[j] = deltaRow * deltaRow.T
70 # 径向基函数的高斯版本
71 K = exp(K / (-1 * kTup[1] ** 2)) # divide in NumPy is element-wise not matrix like Matlab
72 else:
73 raise NameError('Houston We Have a Problem -- That Kernel is not recognized')
74 return K
75
76
77def loadDataSet(fileName):

Callers 3

__init__Method · 0.85
testRbfFunction · 0.85
testDigitsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected