Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Un perceptrón es una neurona artificial, y, por tanto, una unidad de red neuronal.
El perceptrón efectúa cálculos para detectar características o tendencias en los
datos de entrada.
class Ventana():
def __init__(self, master):
self.master = master
self.w1 = tk.IntVar()
self.w2 = tk.IntVar()
self.bias = tk.IntVar()
self.guardaX = 0
self.valor = 0
self.datosX = []
self.datosY = []
self.datos = []
self.fig = plt.figure(figsize=(6, 4))
self.ax = self.fig.add_subplot(111)
self.fig.patch.set_facecolor('xkcd:aqua')
set_xlim = [-10, 10]
set_ylim = [-10, 10]
zeros = [0, 0]
self.ax.plot(set_xlim, zeros, 'k')
self.ax.plot(zeros, set_ylim, 'k')
plt.xlabel('X-axis', fontsize=10)
plt.ylabel('Y-axis', fontsize=10)
self.ax.set_title("Perceptron")
self.canvas = FigureCanvasTkAgg(self.fig, master=self.master)
self.canvas.draw()
self.canvas.flush_events()
self.canvas.get_tk_widget().place(x=0, y=0)
toolbar = NavigationToolbar2Tk(self.canvas, self.master)
self.canvas.mpl_connect("button_press_event", self.mouse)
tk.Label(self.master, text="w1").place(x=30, y=420)
self.val_w1 = tk.Entry(self.master, textvariable=self.w1)
self.val_w1.place(x=60, y=420)
tk.Label(self.master, text="w2").place(x=150, y=420)
self.val_w2 = tk.Entry(self.master, textvariable=self.w2)
self.val_w2.place(x=170, y=420)
tk.Label(self.master, text="bias").place(x=280, y=420)
self.val_bias = tk.Entry(self.master, textvariable=self.bias)
self.val_bias.place(x=310, y=420)
tk.Button(self.master, text="Perceptron", command=self.linea,
justify="center", width=10, height=2).place(x=400,
y=410)
tk.Button(self.master, text="Reiniciar",
command=self.borrar, activeforeground="#F50743",
width=10, height=2).place(x=490, y=410)
def linea(self):
self.a = -1*(float)(self.val_w1.get())/(float)(self.val_w2.get())
self.b = (float)(self.val_bias.get())/(float)(self.val_w2.get())
self.ax.cla()
plt.title("Perceptron")
set_xlim = [-10, 10]
set_ylim = [-10, 10]
zeros = [0, 0]
self.ax.plot(set_xlim, zeros, 'k')
self.ax.plot(zeros, set_ylim, 'k')
for i in range(len(self.datosX)):
self.operacion = ((self.datosX[i] *
(float)(self.val_w1.get())) +
(self.datosY[i] *
(float)(self.val_w2.get())))-(float)(self.val_bias.get())
if self.operacion > 0.0:
self.ax.scatter(self.datosX[i], self.datosY[i],
color="black")
else:
self.ax.scatter(self.datosX[i], self.datosY[i],
color="red")
plt.axline((self.guardaX, self.guardaX*self.a+self.b),
slope=self.a, color="blue")
self.canvas.draw()
def borrar(self):
self.datos = []
self.datosX = []
self.datosY = []
self.ax.cla()
set_xlim = [-10, 10]
set_ylim = [-10, 10]
zeros = [0, 0]
self.ax.plot(set_xlim, zeros, 'k')
self.ax.plot(zeros, set_ylim, 'k')
plt.xlabel('X-axis', fontsize=10)
plt.ylabel('Y-axis', fontsize=10)
self.ax.set_title("Perceptron")
self.canvas.draw()
root = tk.Tk()
root.title("Perceptron")
root.geometry("610x510+0+0")
app = Ventana(root)
tk.mainloop()
Conclusiones.
Las redes neuronales son la base de la inteligencia artificial y conocemos al
perceptrón como la más básica de estas, por tanto, se sientan las bases de lo que
se verá en el curso al realizar esta práctica.
Bibliografía.
Rédac, T. (2022, 7 julio). Perceptrón: ¿Qué es y para qué sirve? Formation
Data Science | DataScientest.com. Recuperado 6 de septiembre de
2022, de https://datascientest.com/es/perceptron-que-es-y-para-que-
sirve