Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7866873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:32:20+00:00 2026-06-03T00:32:20+00:00

I am new to machine learning in python, therefore forgive my naive question. Is

  • 0

I am new to machine learning in python, therefore forgive my naive question. Is there a library in python for implementing neural networks, such that it gives me the ROC and AUC curves also. I know about libraries in python which implement neural networks but I am searching for a library which also helps me in plotting ROC, DET and AUC curves.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T00:32:22+00:00Added an answer on June 3, 2026 at 12:32 am

    In this case it makes sense to divide your question in 2 topics, since neural networks are hardly directly related to ROC curves.

    Neural Networks

    I think there’s nothing better to learn by example, so I’ll show you an approach to your problem using a binary classification problem trained by a Feed-Forward neural network, and inspired by this tutorial from pybrain.

    First thing is to define a dataset. The easiest way to visualize is to use a binary dataset on a 2D plane, with points generated from normal distributions, each of them belonging to one of the 2 classes. This will be linearly separable in this case.

    from pybrain.datasets            import ClassificationDataSet
    from pybrain.utilities           import percentError
    from pybrain.tools.shortcuts     import buildNetwork
    from pybrain.supervised.trainers import BackpropTrainer
    from pybrain.structure.modules   import SoftmaxLayer
    
    from pylab import ion, ioff, figure, draw, contourf, clf, show, hold, plot
    from scipy import diag, arange, meshgrid, where
    from numpy.random import multivariate_normal
    
    means = [(-1,0),(2,4),(3,1)]
    cov = [diag([1,1]), diag([0.5,1.2]), diag([1.5,0.7])]
    n_klass = 2
    alldata = ClassificationDataSet(2, 1, nb_classes=n_klass)
    for n in xrange(400):
        for klass in range(n_klass):
            input = multivariate_normal(means[klass],cov[klass])
            alldata.addSample(input, [klass])
    

    To visualize, it looks something like this:
    dataset

    Now you want to split it into training and test set:

    tstdata, trndata = alldata.splitWithProportion(0.25)
    
    trndata._convertToOneOfMany()
    tstdata._convertToOneOfMany()
    

    And to create your network:

    fnn = buildNetwork( trndata.indim, 5, trndata.outdim, outclass=SoftmaxLayer )
    
    trainer = BackpropTrainer( fnn, dataset=trndata, momentum=0.1, verbose=True,             weightdecay=0.01)
    
    ticks = arange(-3.,6.,0.2)
    X, Y = meshgrid(ticks, ticks)
    # need column vectors in dataset, not arrays
    griddata = ClassificationDataSet(2,1, nb_classes=n_klass)
    for i in xrange(X.size):
        griddata.addSample([X.ravel()[i],Y.ravel()[i]], [0])
    griddata._convertToOneOfMany()  # this is still needed to make the fnn feel comfy
    

    Now you need to train your network and see what results you get in the end:

    for i in range(20):
        trainer.trainEpochs( 1 )
        trnresult = percentError( trainer.testOnClassData(),
                                  trndata['class'] )
        tstresult = percentError( trainer.testOnClassData(
               dataset=tstdata ), tstdata['class'] )
    
        print "epoch: %4d" % trainer.totalepochs, \
              "  train error: %5.2f%%" % trnresult, \
              "  test error: %5.2f%%" % tstresult
    
        out = fnn.activateOnDataset(griddata)
        out = out.argmax(axis=1)  # the highest output activation gives the class
        out = out.reshape(X.shape)
    
        figure(1)
        ioff()  # interactive graphics off
        clf()   # clear the plot
        hold(True) # overplot on
        for c in range(n_klass):
            here, _ = where(tstdata['class']==c)
            plot(tstdata['input'][here,0],tstdata['input'][here,1],'o')
        if out.max()!=out.min():  # safety check against flat field
            contourf(X, Y, out)   # plot the contour
        ion()   # interactive graphics on
        draw()  # update the plot
    

    Which gives you a very bad boundary at the beginning:
    train-start

    But in the end a pretty good result:

    train-end

    ROC curves

    As for ROC curves, here is a nice and simple Python library to do it on a random toy problem:

    from pyroc import *
    random_sample  = random_mixture_model()  # Generate a custom set randomly
    
    #Example instance labels (first index) with the decision function , score (second index)
    #-- positive class should be +1 and negative 0.
    roc = ROCData(random_sample)  #Create the ROC Object
    roc.auc() #get the area under the curve
    roc.plot(title='ROC Curve') #Create a plot of the ROC curve
    

    Which gives you a single ROC curve:
    ROC-single

    Of course you can also plot multiple ROC curves on the same graph:

    x = random_mixture_model()
    r1 = ROCData(x)
    y = random_mixture_model()
    r2 = ROCData(y)
    lista = [r1,r2]
    plot_multiple_roc(lista,'Multiple ROC Curves',include_baseline=True)
    

    ROC-multiple

    (remember that the diagonal just means that your classifier is random and that you’re probably doing something wrong)

    You can probably easily use your modules in any of your classification tasks (not limited to neural networks) and it will produce ROC curves for you.

    Now to get the class/probability needed to plot your ROC curve from your neural network, you just need to look at the activation of your neural network: activateOnDataset in pybrain will give you the probability for both classes (in my example above we just take the max of probabilities to determine which class to consider). From there, just transform it to the format expected by PyROC like for random_mixture_model and it should give you your ROC curve.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm implementing a new machine learning algorithm in Java that extracts a prototype datastructure
Is there a machine learning concept (algorithm or multi-classifier system) that can detect the
Background: I'm doing machine learning research, and want to use the FANN library to
I'm pretty new in the field of machine learning (even if I find it
I'm fairly new at machine learning and text mining in general. It has come
I'm planning on running a machine learning algorithm that learns node values and edge
so I'm using Weka Machine Learning Library's JAVA API and I have the following
I am doing the text categorization machine learning problem using Naive Bayes. I have
I'm using Weka Machine learning library's Java API... I'm trying to calculate the distance
I am new in machine learning and computing probabilities. This is an example from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.