Пример #1
0
def get_pred(x0, X_train0, n=20):

    xs = [
        np.insert(x[lenOfFre:lenOfFre + 21], 0,
                  dis(x0 - x0[10], x[0:lenOfFre] - x[10])) for x in X_train0
    ]

    xs1 = np.asarray(xs)

    #dis2= (dis(xtrain[1,0:lenOfFre],x[0:lenOfFre]) for x in xtrain[0:5,:])

    ind = np.lexsort((xs1[:, 1], xs1[:, 0]))

    xs_sort = xs1[ind]

    xtrain_1 = xs_sort[0:n]

    #xtrain_1 = xs1

    #s_weight = [1/x for x in xs1[0,:]]

    xx = xtrain_1[:, 1:17]
    #    clf = linear_model.LinearRegression()
    xp5 = np.zeros(5)
    for i in range(1, 6):
        yy = xtrain_1[:, 16 + i]
        #clf = svm.SVR(C=10000)
        clf = linear_model.LinearRegression()
        clf.fit(xx, yy)
        xp0 = X_valid0[nx, lenOfFre:lenOfFre + 16]
        xp = clf.predict(xp0)
        xp5[i - 1] = xp
        #print xp ,X_valid0[nx,lenOfFre+15+i]
    return xp5
Пример #2
0
def check_link(v, s, threshold):
    print('v shape: ', v.shape)
    print('s shape: ', s.shape)
    res = dis(v, s) < threshold
    if res.all():
        return True
    else:
        return False
Пример #3
0
def get_treshold(vecs):
    mu = float(input('Enter the threshold hyperparameter mu: '))
    sample = vecs[np.random.choice(vecs.shape[0], 500, replace=False), :]
    distances = []
    len = sample.shape[1]
    for i in range(len):
        for j in range(len):
            distances.append(dis(sample[i], sample[j]))
    res = np.mean(array(distances))
    print('The average distance of sample: ', res)
    res /= mu
    return res
Пример #4
0
def check_link(v, s, threshold):
    res = dis(v, s) < np.sqrt(threshold)
    if res.all():
        return True
    else:
        return False
Пример #5
0
def check_link_by_distance(v, s, threshold):
    res = dis(v, s) < threshold
    if res.all():
        return True
    else:
        return False