Giter VIP home page Giter VIP logo

naive_bayes_text_classifier's Introduction

アプリの使い方

記事の一覧

  • データベースに保存されている記事データのタイトル、URL、カテゴリを確認できます。

記事の追加

  • URLを入力することで、テキスト分類器により記事のカテゴリを判定し、データベースにデータを保存します。

記事の修正

  • データベースに保存されている記事データを変更できます。

実装について

テキスト分類器の学習

  • /classifier/cms/training.pyをコマンドプロンプト上で実行することで学習されるようにしました。
  • 8つのカテゴリそれぞれ、記事がリストになっているページ(例: https://gunosy.com/categories/1) の6ページから19ページまでを訓練データとしました。
    ※1ページから5ページまでは分類器の評価用に使用しています。
  • 学習により計算された各カテゴリの事前確率、単語の出現回数等はpickleによりシリアライズすることで保存しています。

naive bayesによるテキスト分類器部分について

  • 記事URLから本文をスクレイピングし、形態素解析により名詞のみを取り出し、カテゴリ毎の事後確率を計算しています。
  • 学習結果はpickleでデシリアライズして取り出しています。
  • 事後確率の計算では、アンダーフロー防止のため対数をとっています。
  • ラプラススムージングを採用しています。

分類器の評価

  • /classifier/cms/evaluation.pyをコマンドプロンプト上で実行することでカテゴリ別及び全体の精度(正しいカテゴリの判別率)が計算されるようにしました。

  • 精度は下記の通りです。

カテゴリ 精度
合計 0.7725
グルメ 0.97
IT・科学 0.96
スポーツ 0.93
国内 0.67
コラム 0.83
エンタメ 0.75
海外 0.83
おもしろ 0.24

naive_bayes_text_classifier's People

Contributors

nrryuya avatar

Watchers

James Cloos avatar

naive_bayes_text_classifier's Issues

カテゴリ一覧は定数として別ファイルで定義する

使用したライブラリをrequirements.txtとして記述する

githubのコードは異なる環境で動作することを期待するものです
現状ではどのライブラリが使われているのかわからず、djangoを起動させることができません.

pythonの場合requirements.txtまたはsetup.pyで記述します.

requirements.txtのほうが楽なのでrequirements.txtを記述することを今回はやってみましょう

参考URLは以下です.
http://www.lifewithpython.com/2014/03/python-install-multiple-modules-.html

使用したライブラリとバージョンを上記のように記載してください.

githubでの作業における注意点

  • 1つのissueに対して1つのbranchを対応させて作業する
  • masterブランチへ直接のコミットはしない
  • commitは作業単位にまとめてわかりやすいコミットメッセージを付ける
  • PRには対応するissueを紐付ける
  • issueに対する質問はissueに(例えばgithubの使い方の質問はこちらに書いてください)

モデル等のファイルのパスをsettings.pyに記載する

https://github.com/nrryuya/naive_bayes_text_classifier/blob/master/classifier/classifier/settings.py#L16 BASE_DIR の下に

BASE = os.path.dirname(os.path.abspath(__file__))
with open(os.path.join(BASE, 'word_count.pickle'), mode='rb') as w:
word_count = pickle.load(w)
with open(os.path.join(BASE, 'cat_count.pickle'), mode='rb') as c:
cat_count = pickle.load(c)
with open(os.path.join(BASE, 'prior_probs.pickle'), mode='rb') as p:
prior_probs = pickle.load(p)
で使用しているファイルのパスも書いて、それを使用する用にする。

from django.conf import settings
settings.○○_PATH

とかで呼べるようになります。
(よく分からなかったら、例になるレポジトリ渡すので言って下さい。)

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.