示例#1
0
def get_kkmeans_model(X, X_without_contamination, train_data, num_clusters):
    error_2 = 1000000
    for i in xrange(1, 15):
        try:

            kernelKMeans = KernelKMeans(n_clusters=num_clusters,
                                        max_iter=1000,
                                        verbose=0,
                                        kernel='rbf',
                                        gamma=2**-i)
            kernelKMeans.fit(X)
            predict = kernelKMeans.predict(X_without_contamination)
            #print predict
            error = get_minimum_score(predict, train_data, num_clusters)
            #print error
            if error < error_2:
                error_2 = error
                kernelKMeans_model = kernelKMeans
                gamma = 2**-i
        except:
            pass
    kernelKMeans_model.predict(X_without_contamination)
    #print gamma
    #raw_input('ingrese')
    return kernelKMeans_model, gamma
示例#2
0
def get_kkmeans_model(X, X_without_contamination, train_data):
    error_2 = 1000000
    for i in xrange(15):
        try:
            kernelKMeans = KernelKMeans(n_clusters=3, max_iter=1000, verbose=0,kernel='rbf',gamma=2**-i)
            kernelKMeans.fit_predict(X)
            predict = kernelKMeans.predict(X_without_contamination)
            error = get_minimum_score(predict,train_data)
            if error < error_2 : 
                error_2 = error
                kernelKMeans_model = kernelKMeans
                gamma = 2**-i            
        except:
            pass
    return kernelKMeans_model,  gamma
示例#3
0
def get_kkmeans_model(X, X_without_contamination, train_data):
    error_2 = 1000000
    for i in xrange(15):
        try:
            kernelKMeans = KernelKMeans(n_clusters=3,
                                        max_iter=1000,
                                        verbose=0,
                                        kernel='rbf',
                                        gamma=2**-i)
            kernelKMeans.fit_predict(X)
            predict = kernelKMeans.predict(X_without_contamination)
            error = get_minimum_score(predict, train_data)
            if error < error_2:
                error_2 = error
                kernelKMeans_model = kernelKMeans
                gamma = 2**-i
        except:
            pass
    return kernelKMeans_model, gamma
def get_kkmeans_model(X, X_without_contamination, train_data,num_clusters):
    error_2 = 1000000
    for i in xrange(1,15):
        try:

            kernelKMeans = KernelKMeans(n_clusters=num_clusters, max_iter=1000, verbose=0,kernel='rbf',gamma=2**-i)
            kernelKMeans.fit(X)
            predict = kernelKMeans.predict(X_without_contamination)
            #print predict
            error = get_minimum_score(predict,train_data,num_clusters)
            #print error
            if error < error_2 : 
                error_2 = error
                kernelKMeans_model = kernelKMeans
                gamma = 2**-i   
        except:
            pass
    kernelKMeans_model.predict(X_without_contamination)
    #print gamma
    #raw_input('ingrese')
    return kernelKMeans_model,  gamma