{"id":14966077,"url":"https://github.com/titsuki/raku-algorithm-libsvm","last_synced_at":"2025-10-25T13:31:05.735Z","repository":{"id":40653852,"uuid":"77973644","full_name":"titsuki/raku-Algorithm-LibSVM","owner":"titsuki","description":"A Raku bindings for libsvm","archived":false,"fork":false,"pushed_at":"2023-08-26T12:41:38.000Z","size":192,"stargazers_count":8,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-31T07:21:45.125Z","etag":null,"topics":["libsvm","perl6","raku","rakulang","zef"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/titsuki.png","metadata":{"files":{"readme":"README.md","changelog":"Changes","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-01-04T02:40:33.000Z","updated_at":"2023-02-16T19:26:04.000Z","dependencies_parsed_at":"2024-01-06T13:08:17.346Z","dependency_job_id":"2ea49208-63ad-407b-adfd-9794ddcd75af","html_url":"https://github.com/titsuki/raku-Algorithm-LibSVM","commit_stats":null,"previous_names":["titsuki/p6-algorithm-libsvm"],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/titsuki%2Fraku-Algorithm-LibSVM","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/titsuki%2Fraku-Algorithm-LibSVM/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/titsuki%2Fraku-Algorithm-LibSVM/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/titsuki%2Fraku-Algorithm-LibSVM/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/titsuki","download_url":"https://codeload.github.com/titsuki/raku-Algorithm-LibSVM/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238147585,"owners_count":19424287,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["libsvm","perl6","raku","rakulang","zef"],"created_at":"2024-09-24T13:35:47.713Z","updated_at":"2025-10-25T13:31:05.372Z","avatar_url":"https://github.com/titsuki.png","language":"C++","readme":"[![Actions Status](https://github.com/titsuki/raku-Algorithm-LibSVM/workflows/test/badge.svg)](https://github.com/titsuki/raku-Algorithm-LibSVM/actions)\n\nNAME\n====\n\nAlgorithm::LibSVM - A Raku bindings for libsvm\n\nSYNOPSIS\n========\n\nEXAMPLE 1\n---------\n\n    use Algorithm::LibSVM;\n    use Algorithm::LibSVM::Parameter;\n    use Algorithm::LibSVM::Problem;\n    use Algorithm::LibSVM::Model;\n\n    my $libsvm = Algorithm::LibSVM.new;\n    my Algorithm::LibSVM::Parameter $parameter .= new(svm-type =\u003e C_SVC,\n                                                      kernel-type =\u003e RBF);\n    # heart_scale is here: https://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/binary/heart_scale\n    my Algorithm::LibSVM::Problem $problem = Algorithm::LibSVM::Problem.from-file('heart_scale');\n    my @r = $libsvm.cross-validation($problem, $parameter, 10);\n    $libsvm.evaluate($problem.y, @r).say; # {acc =\u003e 81.1111111111111, mse =\u003e 0.755555555555556, scc =\u003e 1.01157627463546}\n\nEXAMPLE 2\n---------\n\n    use Algorithm::LibSVM;\n    use Algorithm::LibSVM::Parameter;\n    use Algorithm::LibSVM::Problem;\n    use Algorithm::LibSVM::Model;\n\n    sub gen-train {\n      my $max-x = 1;\n      my $min-x = -1;\n      my $max-y = 1;\n      my $min-y = -1;\n      my @x;\n      my @y;\n      do for ^300 {\n          my $x = $min-x + rand * ($max-x - $min-x);\n          my $y = $min-y + rand * ($max-y - $min-y);\n\n          my $label = do given $x, $y {\n              when ($x - 0.5) ** 2 + ($y - 0.5) ** 2 \u003c= 0.2 {\n                  1\n              }\n              when ($x - -0.5) ** 2 + ($y - -0.5) ** 2 \u003c= 0.2 {\n                  -1\n              }\n              default { Nil }\n          }\n          if $label.defined {\n              @y.push: $label;\n              @x.push: [$x, $y];\n          }\n      }\n      (@x, @y)\n    }\n\n    my (@train-x, @train-y) := gen-train;\n    my @test-x = 1 =\u003e 0.5e0, 2 =\u003e 0.5e0;\n    my $libsvm = Algorithm::LibSVM.new;\n    my Algorithm::LibSVM::Parameter $parameter .= new(svm-type =\u003e C_SVC,\n                                                      kernel-type =\u003e LINEAR);\n    my Algorithm::LibSVM::Problem $problem = Algorithm::LibSVM::Problem.from-matrix(@train-x, @train-y);\n    my $model = $libsvm.train($problem, $parameter);\n    say $model.predict(features =\u003e @test-x)\u003clabel\u003e # 1\n\nDESCRIPTION\n===========\n\nAlgorithm::LibSVM is a Raku bindings for libsvm.\n\nMETHODS\n-------\n\n### cross-validation\n\nDefined as:\n\n    method cross-validation(Algorithm::LibSVM::Problem $problem, Algorithm::LibSVM::Parameter $param, Int $nr-fold --\u003e List)\n\nConducts `$nr-fold`-fold cross validation and returns predicted values.\n\n### train\n\nDefined as:\n\n    method train(Algorithm::LibSVM::Problem $problem, Algorithm::LibSVM::Parameter $param --\u003e Algorithm::LibSVM::Model)\n\nTrains a SVM model.\n\n  * `$problem` The instance of Algorithm::LibSVM::Problem.\n\n  * `$param` The instance of Algorithm::LibSVM::Parameter.\n\n### **DEPRECATED** load-problem\n\nDefined as:\n\n    multi method load-problem(\\lines --\u003e Algorithm::LibSVM::Problem)\n    multi method load-problem(Str $filename --\u003e Algorithm::LibSVM::Problem)\n\nLoads libsvm-format data.\n\n### load-model\n\nDefined as:\n\n    method load-model(Str $filename --\u003e Algorithm::LibSVM::Model)\n\nLoads libsvm model.\n\n### evaluate\n\nDefined as:\n\n    method evaluate(@true-values, @predicted-values --\u003e Hash)\n\nEvaluates the performance of the three metrics (i.e. accuracy, mean squared error and squared correlation coefficient)\n\n  * `@true-values` The array that contains ground-truth values.\n\n  * `@predicted-values` The array that contains predicted values.\n\n### nr-feature\n\nDefined as:\n\n    method nr-feature(--\u003e Int:D)\n\nReturns the maximum index of all the features.\n\nROUTINES\n--------\n\n### parse-libsvmformat\n\nDefined as:\n\n    sub parse-libsvmformat(Str $text --\u003e List) is export\n\nIs a helper routine for handling libsvm-format text.\n\nCAUTION\n=======\n\nDON'T USE `PRECOMPUTED` KERNEL\n------------------------------\n\nAs a workaround for [RT130187](https://rt.perl.org/Public/Bug/Display.html?id=130187), I applied the patch programs (e.g. [src/3.22/svm.cpp.patch](src/3.22/svm.cpp.patch)) for the sake of disabling random access of the problematic array.\n\nSadly to say, those patches drastically increase the complexity of using `PRECOMPUTED` kernel.\n\nSEE ALSO\n========\n\n  * libsvm [https://github.com/cjlin1/libsvm](https://github.com/cjlin1/libsvm)\n\n  * RT130187 [https://rt.perl.org/Public/Bug/Display.html?id=130187](https://rt.perl.org/Public/Bug/Display.html?id=130187)\n\nAUTHOR\n======\n\ntitsuki \u003ctitsuki@cpan.org\u003e\n\nCOPYRIGHT AND LICENSE\n=====================\n\nCopyright 2016 titsuki\n\nThis library is free software; you can redistribute it and/or modify it under the terms of the MIT License.\n\nlibsvm ( https://github.com/cjlin1/libsvm ) by Chih-Chung Chang and Chih-Jen Lin is licensed under the BSD 3-Clause License.\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftitsuki%2Fraku-algorithm-libsvm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftitsuki%2Fraku-algorithm-libsvm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftitsuki%2Fraku-algorithm-libsvm/lists"}