# -*- encoding: utf8 -*-

import numpy as np

from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split

from lvq import SilvqModel
from lvq.utils import plot2d

def main():
    # Load dataset
    dataset = np.loadtxt('data/artificial_dataset1.csv', delimiter=',')
    x = dataset[:, :-1].astype('float64')
    y = dataset[:, -1].astype('int64')
    # Split dataset into training set and test set
    x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=3, shuffle=True, stratify=y)

    # Generating model
    model = SilvqModel(x.shape[1], theta=0.8, bias_type='ls')
    # Training the model
    model.fit(x_train, y_train, epochs=30)
    # Predict the response for test dataset
    y_predict = model.predict(x_test)

    # Evaluating the model
    print('Accuracy: %.3f' %accuracy_score(y_test, y_predict))
    # Plot prediction results and prototypes
    plot2d(model, x, y, title='Artificial dataset1')

if __name__ == '__main__':
    main()

[((13, 14, 13, 71), 'numpy.loadtxt', 'np.loadtxt', (), '', True, 'import numpy as np\n'), ((17, 39, 17, 118), 'sklearn.model_selection.train_test_split', 'train_test_split', (), '', False, 'from sklearn.model_selection import train_test_split\n'), ((20, 12, 20, 61), 'lvq.SilvqModel', 'SilvqModel', (), '', False, 'from lvq import SilvqModel\n'), ((29, 4, 29, 52), 'lvq.utils.plot2d', 'plot2d', (), '', False, 'from lvq.utils import plot2d\n'), ((27, 28, 27, 61), 'sklearn.metrics.accuracy_score', 'accuracy_score', ({(27, 43, 27, 49): 'y_test', (27, 51, 27, 60): 'y_predict'}, {}), '(y_test, y_predict)', False, 'from sklearn.metrics import accuracy_score\n')]