Beispiel #1
0
from som import SOM

if __name__ == "__main__":
    a = SOM(5, 5, 3, 2, False, 0.05)
    a.train(100,
            [[[0, 0, 0], [0, 0]], [[1, 0, 0], [0, 1]], [[0, 1, 0], [1, 0]],
             [[1, 1, 1], [1, 1]]])
    print("Prediction 0 and 0 ,", round(a.predict([0, 0, 0])[0, 1]))
Beispiel #2
0
    for col in range(1, num_cols):
        col_values.append(input_sheet.col_values(col)[1:])
    x = np.array(col_values, dtype='|S4')
    y = x.astype(np.float)
    maxs = [max(y[col]) for col in range(0, num_cols - 1)]
    mins = [min(y[col]) for col in range(0, num_cols - 1)]
    data_points = []
    for row in range(1, num_rows):
        values = []
        for col in range(1, num_cols):
            values.append(
                (float(input_sheet.cell(row, col).value) - mins[col - 1]) /
                (maxs[col - 1] - mins[col - 1]))
        d = DataPoint(values, int(output_sheet.cell(row, 0).value))
        data_points.append(d)
    print(num_rows - 1, " points with dimesion=", num_cols - 1, " are added")
    return data_points


data_points = load_data("722.xlsx")
s = SOM(2, 8, 27)
s.load_input_data(data_points)
s.fit(2, 0.1)

v = LVQ(2, 6, 5)
v.load_data(data_points)
v.train(5, 0.01, 2)

s.predict(data_points)
v.predict(data_points)
Beispiel #3
0
import numpy as np
import pandas as pd
from som import SOM
from sklearn.datasets import load_boston
from sklearn.preprocessing import StandardScaler

# read in data
boston = load_boston().data
# standard scale data
ss = StandardScaler()
X = ss.fit_transform(boston)

# instantiate SOM
som = SOM(X, 3, 3, 1, 100, 0.01)
# train model
tree, weights, winners, distances = som.train(X)
# print data
# print(weights)
print(set(winners))


dist, ind = som.predict(X, tree)
print(set([x[0] for x in ind]))
Beispiel #4
0
sigma = 1

learning_rate = 1

sigma_decrease_rate = 0

som = SOM(inputs,
          weights,
          sigma=sigma,
          learning_rate=learning_rate,
          sigma_decrease_rate=sigma_decrease_rate,
          epochs=10)
som.train(ignore_hk=True, display=True)
points = [[1, 4], [6, 2], [1, 3], [5, 1], [4, 0], [0, 4], [3, 4]]

predictions = som.predict(points, ignore_hk=True, display=True)

p, m = som.prediction_line(display=True)


def med(points, p, m):
    y = []
    for point in points:
        y.append(m * (point - p[0]) + p[1])
    return y


plt.grid()
for point, prediction in zip(points, predictions):
    x, y = point
    color, label = ("blue",