머신러닝 알고리즘 - 피썬(Python 소스)

4572 단어 기계 학습
#*-encoding:utf-8-*

########################################################################################################
# Summary:  
# Author: Kurt
# Date: 2016/3/23
########################################################################################################

#-------------------------------------------------------------------------------------------------------
#  
def createData():
    data = [[3, 3, 1], [4, 3, 1], [1, 1, -1]]
    return data

#-------------------------------------------------------------------------------------------------------
#  
def update(weight, tuple, step):
    weight[0] += step * tuple[-1]
    for i in range(len(tuple) -1):
        weight[i+1] += step * tuple[i] * tuple[-1]
    return weight


#-------------------------------------------------------------------------------------------------------
#  
def calculate(weight, tuple):
    sum = weight[0]
    for i in range(len(tuple) -1):
        sum += weight[i+1] * tuple[i]
    sum *= tuple[-1]
    print sum
    return sum

#-------------------------------------------------------------------------------------------------------
#  
def percetron(dataSet, step = 1):
    w = []  #  , b
    isNotDone = True
    #  
    for i in range(len(dataSet[0])):
        w.append(0)
    while(isNotDone):
        print "

Scan the data again"
# for tuple in dataSet: # if(calculate(w, tuple) <= 0): print "Error point: " print tuple isNotDone = True update(w, tuple, step) print "----->>>New weight is ", w break else: isNotDone = False return w

좋은 웹페이지 즐겨찾기