#Import toy data and target
X = pd.read_csv('../../data/simulated/mvnsim/mvnsim' + dataset + '.csv',
                sep=',',
                header=0,
                index_col=0).as_matrix()
y = np.load('../../data/simulated/mvnsim/target' + dataset + '.npy')
print(y)
print(y.shape)
print(X.shape)

#Plot initial data
plot_scatter(
    X,
    y,
    'Initial data',
    x_label='x coordinate',
    y_label='y coordinate',
    #output='save',
    output='show',
    #path='../../figs/out/%s/%s/initial.png' % (scriptname, dataset)
)

## PREPROCESSING ##

#Scale initial data to centre data

X_scaled = scale(X)

plot_scatter(
    X_scaled,
    y,
    'Scaled data',
Esempio n. 2
0
    kpca_kernels = []

    for kernel, abbreviation, kpca in kpcas:

        if kernel == 'Laplacian KPCA':
            X_kpca = kpca.fit_transform(K_lap)
        else:
            X_kpca = kpca.fit_transform(X_scaled)

        p2.plot_scatter(
            X_kpca,
            y,
            'First 2 principal components after %s' % kernel,
            gamma=gamma,
            x_label='Principal component 1',
            y_label='Principal component 2',
            #output = 'show',
            #output='save',
            #path='%s%s_%spca_gamma%s.png' % (filepath, nowtime, abbreviation, gamma)
        )
        #print('\nScatter plot of first two principal components after %sPCA for dataset %s saved.' % (kernel, dataset))

        kpca_kernels.append(kernel)

        # Declare names of models deployed and ROC AUC for each model
        mdl_names = []
        mean_aucs = []

        for model_name, model_abv, model in models:
Esempio n. 3
0
cv = StratifiedKFold(n_splits=10, random_state=10)

# Declare KPCA kernels deployed

kpca_kernels = []

for kernel, abbreviation, kpca in kpcas:

    X_kpca = kpca.fit_transform(X_scaled)

    plot_scatter(
        X_kpca,
        y,
        'First 2 principal components after %sPCA' % kernel,
        gamma=gamma,
        x_label='Principal component 1',
        y_label='Principal component 2',
        #output = 'show',
        output='save',
        path='../../figs/out/%s/%s/%spca_gamma%s.png' %
        (scriptname, dataset, abbreviation, gamma))
    print(
        '\nScatter plot of first two principal components after %sPCA for dataset %s saved.'
        % (kernel, dataset))

    X_kpca = kpca.fit_transform(X)

    kpca_kernels.append(kernel)

    # Declare names of models deployed
    mdl_names = []
# Name of script to trace where images came from
scriptname = 'gs_tune_1_2'

#Select current toy dataset
dataset = '013'

#Import toy data and target
X = pd.read_csv('../../data/simulated/mvnsim/mvnsim' + dataset + '.csv', sep=',', header=0, index_col=0).as_matrix()
y = np.load('../../data/simulated/mvnsim/target' + dataset + '.npy')
 
#Plot initial data
plot_scatter(X, 
             y, 
             'Initial data', 
             x_label='x coordinate', 
             y_label='y coordinate',
             output='save',
             path='../../figs/out/%s/%s/initial.png' % (scriptname, dataset)
             )


## PREPROCESSING ##

#Scale initial data to centre data

X_scaled = scale(X)

plot_scatter(X_scaled,
             y, 'Scaled data',
             x_label='x coordinate',
             y_label='y coordinate',             
#Create directory if directory does not exist
filepath = '../../figs/out/%s/%s/' % (scriptname, dataset)

if not os.path.exists(filepath):
    os.makedirs(filepath)

#Import toy data and target
X = pd.read_csv('../../data/simulated/mvnsim/mvnsim' + dataset + '.csv', sep=',', header=0, index_col=0).as_matrix()
y = np.load('../../data/simulated/mvnsim/target' + dataset + '.npy')

#Plot initial data
plot_scatter(X,
             y,
             'Initial data',
             x_label='x coordinate',
             y_label='y coordinate',
             #output='save',
             #path='%sinitial.png' % filepath
             output = 'show',
             )


## PREPROCESSING ##

#Scale initial data to centre data

X_scaled = scale(X)

plot_scatter(X_scaled,
             y, 'Scaled data',
             x_label='x coordinate',
        # To utilise precomputed kernel(s)
        if kernel == 'Laplacian KPCA':
            X_kpca = kpca.fit_transform(kpca_lap)
        #elif kernel == 'Chi Squared KPCA':
        #    X_kpca = kpca.fit_transform(kpca_chi)
        else:
            X_kpca = kpca.fit_transform(X_scaled)

        p2f.plot_scatter(
            X_kpca,
            y,
            'First 2 principal components after %s' % kernel,
            gamma=gamma,
            x_label='Principal component 1',
            y_label='Principal component 2',
            #output = 'show',
            output='save',
            path='%s%s_%s_gamma%s.png' %
            (filepath, nowtime, abbreviation, gamma),
            writepath='%s%s_%s_%s_plottingdata.txt' %
            (plotpath, nowtime, scriptname, dataset),
            dataset=dataset,
            kernel=kernel,
        )

        print(
            '\nScatter plot of first two principal components after %s for dataset %s saved.'
            % (kernel, dataset))

        kpca_kernels.append(kernel)

        # Declare names of models deployed
Esempio n. 7
0
X, y = make_circles(n_samples=1000, factor=.3, noise=.05, random_state=12)

gamma = 5

x_kerns = [("linear", linear_kernel(X)),
           ("gaussian", rbf_kernel(X, gamma=gamma)),
           ("laplacian", laplacian_kernel(X, gamma=gamma)),
           ("cosine", cosine_similarity(X)), ("sigmoid", sigmoid_kernel(X))]
fig = plt.figure(figsize=(8, 6))

p2f.plot_scatter(X,
                 y,
                 '',
                 gamma=gamma,
                 x_label='x coordinate',
                 y_label='y coordinate',
                 cat1='Category 1',
                 cat0='Category 0',
                 output='save',
                 path='%sinit_scatter.png' % imgpath,
                 jspath='%sinit_scatter.js' % jspath)

for k_lab, k_X in x_kerns:

    p2f.plot_scatter(k_X,
                     y,
                     '',
                     gamma=gamma,
                     x_label='x coordinate',
                     y_label='y coordinate',
                     cat1='Category 1',