本文整理汇总了Python中Features.getVector方法的典型用法代码示例。如果您正苦于以下问题:Python Features.getVector方法的具体用法?Python Features.getVector怎么用?Python Features.getVector使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Features
的用法示例。
在下文中一共展示了Features.getVector方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: classify
# 需要导入模块: import Features [as 别名]
# 或者: from Features import getVector [as 别名]
def classify(data, weights, featureSet, algorithm):
length = Features.getLength(featureSet)
results = np.zeros(data.shape[0])
for i in range(data.shape[0]):
if algorithm == 1:
vector = Features.getVector(data[i,0], featureSet)
vector.append(length)
results[i] = predict_one(weights, vector, 0)
else:
vector = Features.getVector(data[i,0], featureSet)
results[i] = predict_one(weights, vector, length)
return results
示例2: perceptron
# 需要导入模块: import Features [as 别名]
# 或者: from Features import getVector [as 别名]
def perceptron(data, maxIterations, featureSet):
length = Features.getLength(featureSet)
rate = 0.1
weights = np.zeros((1,length+1))
i = 0
while i < maxIterations:
for j in range(data.shape[0]):
#print weights
vector = Features.getVector(data[j,0], featureSet)
vector.append(length)
sign = predict_one(weights, vector, 0)
if (data[j,1] == '+' and sign == -1) or (data[j,1] == '-' and sign == 1):
for index in vector:
weights[0,index] = weights[0,index] - rate*sign
i += 1
return weights
示例3: winnow
# 需要导入模块: import Features [as 别名]
# 或者: from Features import getVector [as 别名]
def winnow(data, maxIterations, featureSet):
length = Features.getLength(featureSet)
threshold = length
weights = np.ones((1,length))
i = 0
while i < maxIterations:
for j in range(data.shape[0]):
#print weights
vector = Features.getVector(data[j,0], featureSet)
sign = predict_one(weights, vector, threshold)
if data[j,1] == '+' and sign == -1:
for index in vector:
weights[0,index] = weights[0,index]*2
elif data[j,1] == '-' and sign == 1:
for index in vector:
weights[0,index] = weights[0,index]/2
i += 1
return weights