Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Graph not plotting
#1
Hello All,

I wrote this code and it is compiling well.

For whatever reason its not showing the graph.

I would really appreciate it if you will kindly point out why the graph is not plotting.

import numpy as np
from matplotlib import pyplot as plt

X = np.array([
    [-2, 4, -1],
    [4, 1, -1],
    [1, 6, -1],
    [2, 4, -1],
    [6, 4, -1],
])

Y = np.array([-1,-1,1,1,1])


def svm_sgd_plot(X, Y):
    w = np.zeros(len(X[0]))
    eta = 1
    epochs = 100000
    errors = []

    for epoch in range(1,epochs):
        error = 0
        for i, x in enumerate(X):
            if (Y[i]*np.dot(X[i], w)) < 1:
                w = w + eta * ( (X[i] * Y[i]) + (-2  *(1/epoch)* w) )
                error = 1
            else:
                w = w + eta * (-2  *(1/epoch)* w)
        errors.append(error)
        

        plt.plot(errors, '|')
        plt.ylim(0.5,1.5)
        plt.axes().set_yticklabels([])
        plt.xlabel('Epoch')
        plt.ylabel('Misclassified')
        plt.show()

        return w
Reply
#2
You just defined a function, but didn't run it.
def function(): # define a function
    pass
function() # run the function
Add svm_sgd_plot(X, Y) to your file, and you can see the graph.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Exclamation Error when plotting a graph. Oshadha 3 3,574 Mar-14-2022, 06:47 PM
Last Post: deanhystad
  Plotting simple graph (AttributeError) Laplace12 0 1,344 Jul-28-2021, 10:58 AM
Last Post: Laplace12
  Plotting number on graph william888 1 1,688 Sep-02-2019, 02:36 AM
Last Post: scidam
  Graph Plotting Help Talch 1 2,196 Aug-16-2018, 10:29 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020