Beispiel #1
0
def training_batched_som(map_min_size, map_max_size, nb_models, X_train):
    for i in range(nb_models):
        sm = SOMFactory().build(
            X_train,
            mapsize=[
                random.choice(list(range(map_min_size, map_max_size))),
                random.choice(list(range(map_min_size, map_max_size)))
            ],
            normalization='var',
            initialization='random',
            component_names=names,
            lattice="hexa")
        sm.train(n_job=1,
                 verbose=False,
                 train_rough_len=30,
                 train_finetune_len=100)
        joblib.dump(sm, path + "batched_model_{}.joblib".format(i))
        print("end of training model n°" + str(i))

    # Study the models trained and plot the errors obtained in order to select the best one
    models_pool = glob.glob(path + "batched_model*")
    errors = []
    for model_filepath in models_pool:
        sm = joblib.load(model_filepath)
        topographic_error = sm.calculate_topographic_error()
        quantization_error = sm.calculate_quantization_error()
        errors.append((topographic_error, quantization_error))
    e_top, e_q = zip(*errors)

    plt.scatter(e_top, e_q)
    plt.xlabel("Topographic error")
    plt.ylabel("Quantization error")
    plt.title("Topographic and quantization errors of the models trained")
    plt.show()
Beispiel #2
0
def training_specific_som(map_x_size, map_y_size, X_train):
    sm = SOMFactory().build(X_train,
                            mapsize=[map_x_size, map_y_size],
                            normalization='var',
                            initialization='random',
                            component_names=names,
                            lattice='hexa')
    sm.train(n_job=1,
             verbose=False,
             train_rough_len=30,
             train_finetune_len=100)
    joblib.dump(sm, path + "batched_model_specific{}.joblib".format(0))
    print("Topographic error: " + str(sm.calculate_topographic_error()) +
          ", Quantization error: " + str(sm.calculate_quantization_error()) +
          "\n")
    return (sm)