Esempio n. 1
0
from data_parser import DataParser
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

parser = DataParser('europe.csv')

matrix_standarized = parser.get_standarized_matrix()

# Create a figure instance
fig = plt.figure(1, figsize=(9, 6))

# Create an axes instance
ax = fig.add_subplot(111)

## Custom x-axis labels
ax.set_xticklabels([
    'Area', 'GDP', 'Inflation', 'Life.expect', 'Military', 'Pop.growth',
    'Unemployment'
])

## add patch_artist=True option to ax.boxplot()
## to get fill color
bp = ax.boxplot(matrix_standarized, patch_artist=True)

## change outline color, fill color and linewidth of the boxes
for box in bp['boxes']:
    # change outline color
    box.set(color='#7570b3', linewidth=2)
    # change fill color
    box.set(facecolor='#1b9e77')
Esempio n. 2
0
from kohonen_network import Kohonen
from data_parser import DataParser
import seaborn as sn
import matplotlib.pyplot as plt
import numpy as np

parser = DataParser('europe.csv')

standarized_matrix = np.array(parser.get_standarized_matrix()).T

k_neurons = 15
kohonen = Kohonen(standarized_matrix,
                  k_neurons,
                  iteration_limit=3000,
                  eta=0.0001)
kohonen.train()

som_map = kohonen.construct_nodes_map()
u_matrix = kohonen.build_u_matrix()

countries_string = parser.parse_as_class()
neurons = [[[] for x in range(k_neurons)] for y in range(k_neurons)]
for i in range(len(standarized_matrix)):
    best_i, best_j, best_difference = kohonen.get_best_matching(
        standarized_matrix[i])
    neurons[best_i][best_j].append(countries_string[i][0])
    print("Country: {}, Best neuron: {},{}, Best difference: {}".format(
        countries_string[i][0], best_i, best_j, best_difference))

print('Paises por neurona')
print(neurons)
Esempio n. 3
0
from data_parser import DataParser
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sn
from sklearn.covariance import EmpiricalCovariance
from sklearn.decomposition import PCA 

parser = DataParser('europe.csv')
# print(parser.get_numerical_csv())
# print(np.matrix(parser.get_numerical_csv()).T)

# matrix_for_correlation = np.array(parser.get_numerical_csv(), dtype=float).T
matrix_for_correlation = np.array(parser.get_standarized_matrix())

print('MEDIA (Tiene que tender a 0):', np.mean(matrix_for_correlation), '| STD (Tiene que tender a 1):', np.std(matrix_for_correlation))

# print('ESTANDARIZADA',parser.get_standarized_matrix())

# 'Area','GDP','Inflation','Life.expect','Military','Pop.growth','Unemployment'
matrix_for_correlation_with_keys = {
    'Area': matrix_for_correlation[0],
    'GDP': matrix_for_correlation[1],
    'Inflation': matrix_for_correlation[2],
    'Life.expect': matrix_for_correlation[3],
    'Military': matrix_for_correlation[4],
    'Pop.growth': matrix_for_correlation[5],
    'Unemployment': matrix_for_correlation[6]
}

df = pd.DataFrame(matrix_for_correlation_with_keys, columns=[