当前位置: 首页>>代码示例>>Python>>正文


Python Features.getVector方法代码示例

本文整理汇总了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    
开发者ID:aparolia,项目名称:MLProjects,代码行数:15,代码来源:main.py

示例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 
开发者ID:aparolia,项目名称:MLProjects,代码行数:18,代码来源:main.py

示例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
开发者ID:aparolia,项目名称:MLProjects,代码行数:20,代码来源:main.py


注:本文中的Features.getVector方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。