Giter Site home page Giter Site logo

stfblanchet / magicl Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 1003 KB

A binary classifier that runs from preprocessing to modeling and classification, and automates benchmarking of multiple classifiers to choose the best.

Python 78.16% HTML 21.84%
classification machine-learning tf-idf scikit-learn

magicl's Introduction

MagiClass

Table of contents

General information

MagiClass is a Machine Learning Flask app that performs preprocessing, modeling and text classification tasks so to deliver a tagged dataset via its API.

The current version is focused on English corpora and binary classification (e.g. spam vs. not spam).

Routes

MagiClass offers 3 sub-endpoints which need a directory name and a file name to be specified:

  • .../preprocess/{directory}/{filename}
    the name of the folder followed by the name of the csv file to be preprocessed.
  • .../model/{directory}/{filename}
    the name of the folder followed by the name of the clean json file to be split as train/test dataset.
  • .../classify/{directory}/{filename}
    the name of the folder followed by the name of clean json the file to be tagged.

Modules

1. Preprocessing

This first task allows two types of preprocessing through the parameter 'pipe':

  • 'min': .../preprocess/{directory}/{filename}?pipe=min
    cleaning (i.e. remove urls, emails, phone numbers, special characters) and language detection only
  • 'max': .../preprocess/{directory}/{filename}?pipe=max
    metadata extraction (urls, emails, phone numbers), emphasis markers (series of capital letters, exclamation and question marks) performed before cleaning and language detection so to allow further analysis

Default: 'min'.

Output: json ; also save a json file (clean_{filename}.json) which is stored in 'data/{directory}/dataset/'.

2. Modeling

This second task includes mandatory parameters:

  • 'target': the name of the field that contains the dependant variable - that is Y
    E.g. .../model/spam/train?target=category
  • 'target_value': the value to be encoded 1
    E.g. .../model/spam/train?target=category&target_value=spam
  • 'factor': the name of the field that contains the independant variable - that is X
    E.g. .../model/spam/train?target=category&target_value=spam&factor=text

Customizable parameters are listed below:

  • 'narrow_lang': reduce the dataset to a specific language only, depending on the 'lang' field generated through the preprocessing phase
    E.g. .../model/spam/train?narrow_lang=en
    Default: 'none'
  • 'lemmatizer': if True, lemmatize the text designated as factor using spaCy (En)
    Default: False
  • 'vectorizer': choose between TfidfVectorizer ['tfidf'] and CountVectorizer ['bow'] to be included in the modeling pipeline
    E.g. .../model/spam/train?vectorizer=bow
    Default: 'tfidf'
  • 'resampler': if True, resample the dataset in case the target distribution (sum of target value / sum of not target value) is less than 0.85 or more than 1.15
    Default: True
  • 'classifiers': define one ore more classifiers to be run - available are Naive Bayes algorithms: Multinomial ('MBN'), Bernoulli ('BNB') and Complement ('CNB')
    E.g. .../model/spam/train?classifiers=BNB+MNB
    Default: 'BNB+CNB+MNB'
  • 'mode': if 'single', one classifier has to be specified in the 'classifiers' parameter so the model can be saved with pickle in 'data/{directory}/model/'; otherwise, the listed classifiers are compared across various metrics
    Default: 'benchmark'
  • 'metric': define the core metric to select the best model among 'accuracy', 'roc_auc_score', 'f1', 'precision' and 'recall'
    Default: 'f1' (especially relevant in a binary classification problem)

Output: json ; also save a json file (benchmark.json) which is stored in 'data/{directory}/model/'.

The output provides useful information to evaluate models as well as the quality of the dataset. In addition to the metrics mentioned above, there are given the train accuracy compared with the test accuracy as an overfitting indicator, the size of the train dataset, and the target ratio as an imbalance indicator.

Hyperparameters for Naive Bayes algorithms are automatically tuned using GridSearchCV.

3. Classification

This final task delivers the tagged dataset via .../classify/{directory}/{filename}. There is no need to define paramaters: the ones used in the modeling phase are automatically retrieved from the 'benchmark' json file.

Output: json

Technical requirements

The application is built with Python 3.8 and Flask 1.1.2.

Libraries include Pandas, LangDetect, spaCy, Scikit-Learn.

pip3 install -r requirements.txt

Status

This project is in progress.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Author

License

This project is licensed under the MIT License - see MIT for details.

magicl's People

Contributors

stfblanchet avatar

Stargazers

 avatar

Watchers

 avatar  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.