from sklearn.model_selection import train_test_split
import numpy as np
from sklearn.metrics import mean_squared_error
import modelo
import matplotlib.pyplot as plt

# Leo los datos
A = np.loadtxt( "d.txt" )

X = A[:,0:2]
yi = A[:,2]
y = np.where(yi==0, -1, 1 )

# Dividimos los datos en datos de entrenamiento
# y datos de prueba
X_entrena, X_prueba, y_entrena, y_prueba = train_test_split( X, y, random_state=3 )

salida = modelo.eval( X_entrena.T )

_, n = salida.shape

i = 0
while i < n :
	print( X_entrena[i,0], X_entrena[i,1], salida[0,i] )
	i += 1

salida = modelo.eval( X_prueba.T )
# print( salida.shape )
# print( y_prueba )
# print( salida[0] )
e = mean_squared_error( y_prueba, salida[0] )
print( "# ERMS:", e ) 


fig = plt.figure()
 
# syntax for 3-D projection
ax = plt.axes(projection ='3d')
 
# plotting
salida = modelo.eval( X_entrena.T )

ax.scatter3D( X_entrena[:,0], X_entrena[:,1], salida[0], 'green')
ax.set_title('Graph of the adjusted XOR')
plt.show()

