スキップしてメイン コンテンツに移動

投稿

ラベル(machine learning)が付いた投稿を表示しています

Algorithm::LibLinear Tutorial

About this article This article is meant to be an introduction guide of Algorithm::LibLinear , a Perl binding to the famous LIBLINEAR machine learning toolkit. I've once written an article titled "Algorithm::LibLinear の紹介" ("Introduction to Algorithm::LibLinear,") in Japanese. Today, although some part of the article is outdated, Blogger's access analytics reported me that the article is still popular, and fairly large number of visitors are from English-speaking country. Thus I guessed I should prepare an updated tutorial in English. Notice that what I try to describe here is library usage, not a machine learning methodology. If you are new to machine learning, I recommend to read a practical guide by Chih-Wei Hsu, et al and try LIBSVM/LIBLINEAR using CLI commands at first. As you might see my English skill is not so great. Please don't hesitate to point/correct unclear part of this article and help me to fix it. Installation Algorithm::LibLinear...

Algorithm::SVM の注意点

要旨 Algorithm::SVM は極めて有用だけど API がなんか変なので注意が必要。 詳説 CPAN に Algorithm::SVM 1 というモジュールがあります。これ Support Vector Machine (SVM) 2 を提供する LIBSVM 3 という有名なライブラリの Perl バインディングなのですが、なんか API に癖があるので注意点を解説します。 まず使い方を簡単に紹介します: use strict; use warnings; use Algorithm::SVM; my @data_set; while (<DATA>) { chomp; my ($label, $vector) = split /:\s+/, $_, 2; my @vector = split /,\s+/, $vector; my $data = Algorithm::SVM::DataSet->new( DataSet => \@vector, Label => $label, ); push @data_set, $data; } # 本当はパラメータ調整が要るけど省略。全部デフォルトなのでガウスカーネル利用の C-SVC になる。 my $svm = Algorithm::SVM->new; # 分類器を訓練する。 $svm->train(@data_set); # ラベル1に分類されるべき未知のデータ。 my $test_data = Algorithm::SVM::DataSet->new( DataSet => [ 4.6, 3.2, 1.4, 0.2 ], # ラベルは未知なので仮に 0 とする。単に無視されるので -1 でも 65536 でも 42 でも良い。 Label => 0, ); # 未知データを分類。1 が返るはず。 my $label = $svm->predict($test_data); print "$label\n"; # Iris Data Set (http://archive.ics.uci.edu/ml/datasets/Iris) より...

Algorithm::LibLinear の紹介

Notice: This article is outdated. Please refer an updated English tutorial . 要旨 かなり前になりますが、Algorithm::LibLinear という Perl モジュールを書きました。 CPAN Github これを使うと線形分類器などが高速に学習できます。テキストや画像の分類が応用として期待されます。 LIBLINEAR について LIBLINEAR は LIBSVM と同じ台湾国立大学の Chih-Jen Lin 教授のチームが公開しているオープンソースの機械学習パッケージです。 関数のロジスティック回帰、サポートベクター回帰及び線形 SVM による多クラス分類を行うことができます。LIBSVM と違ってカーネル関数を使うことはできませんが、はるかに高速に動作します。 Algorithm::LibLinear について LIBLINEAR には C++ で書かれたライブラリと、その機能を使って機械学習と分類・関数回帰を行うコマンドラインユーティリティが含まれています。 Algorithm::LibLinear はライブラリの機能を Perl からオブジェクト指向的に利用できるようにした上で、コマンドラインユーティリティの一部機能をライブラリ化して Perl で再実装したものです。 使い方 分類問題を解くときは、 訓練データセットの読み込み・スケーリング 学習器パラメータの設定 分類器の訓練 実データの分類 という手順で行います。 訓練データセットの読み込み 正解ラベルのついたデータを大量に用意して学習させます。 LIBSVM 形式のデータを読み込むか: my $data_set = Algorithm::LibLinear::DataSet->load(string => <<'EOD'); 1 1:0.1 2:0.1 4:0.1 -1 1:0.1 2:-0.1 3:0.1 ... EOD HashRef として表現されたデータを使います: my $data_set = Algorithm::LibLinear::DataSet->new(data_set => [ +{ feature => +{ 1...