GithubHelp home page GithubHelp logo

paudelsagar / multiscorer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stkyr/multiscorer

0.0 1.0 0.0 19 KB

A module for allowing the use of multiple metric functions in scikit's cross_val_score

License: GNU General Public License v3.0

Python 100.00%

multiscorer's Introduction

multiscorer

A module for allowing the use of multiple metric functions in scikit's cross_val_score.

As it has been discussed, Python's SciKit, while it contains a great functionality for computing evaluation metrics of estimators (using cross_val_score), it seems to fail when it comes to computing multiple metrics for the same classifier without trainning it again.

The problem arises because of the scoring parameter of the function which accepts only a single metric name or a single callable.

Module multiscorer of this repo, is a workaround for using any number of metrics in cross_val_score.

Installation

To "install" the module simply download the source code and place it in your project's directory.
(Alternativelly, download and add to your project just multiscorer.py file).

Usage (Quickstart example)

From a Python script, you can write:

from multiscorer import MultiScorer

from sklearn.metrics import accuracy_score, precision_score          # Scikit's libraries for demonstration
from sklearn.model_selection import cross_val_score
from numpy import average

scorer = MultiScorer({                                               # Create a MultiScorer instance
  'accuracy': (accuracy_score, {}),
  'precision': (precision_score, {'average': 'macro'})               # Param 'average' will be passed to precision_score as kwarg 
})

...

cross_val_score(clf, X, target, scoring=scorer, cv=10)               # Use the function with our socrer. Ignore its result 

results = scorer.get_results()                                       # Get a dict of lists containing the scores for each metric

for metric in results.keys():                                        # Iterate and use the results
  print("%s: %.3f" % (metric, average(results[metric])))

Notes

Development and Contributing

This module was something I had the need for while working with Scikit's libraries and I just thought it might help somebody.
For questions, bugs, suggestions etc, feel free to contact me or submit a Pull Request.

multiscorer's People

Contributors

stkyr avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.