Latest 1.0.0
License MIT
Platforms ios 7.0, requires ARC
Frameworks Foundation


KRSVM is implemented SVM of machine learning.


platform :ios, '7.0'
pod "KRSVM", "~> 1.0.0"

How To Get Started


#import "KRSVM.h"


KRSMO *smo = [[KRSVM sharedSVM] useSMO];

Use Linear Kernel Function

[smo.kernel useLinear];

Use RBF Kernel Function

The sigma that could be customized by your wishes, default value is 2.0, but some papers said 0.5, 1.0, 3.0, 5.0 that all can do training. Anyway, just try, nothing else.

[smo.kernel useRBF];
smo.kernel.sigma = 2.0f;

Use Hyperbolic Tangent (tanh) Kernel Function

The alpha of tangent could be customized by your wishes, default value is 1.0, but sometimes to be 2.0 is better, in this sample case we used 0.8 to do regression.

[smo.kernel useTanh];
smo.kernel.alpha = 0.8f;

Training Sample

smo.toleranceError = 0.001f;
smo.maxIteration   = 1000;
smo.constValue     = 1;
[smo.kernel useLinear];

// Setup the groups of classification and the target-value of group
[smo addGroupOfTarget:-1.0f];
[smo addGroupOfTarget:1.0f];

// Patterns
[smo addPatterns:@[@0.0f, @0.0f] target:-1.0f]; // x1
[smo addPatterns:@[@2.0f, @2.0f] target:-1.0f]; // x2
[smo addPatterns:@[@2.0f, @0.0f] target:1.0f];  // x3
[smo addPatterns:@[@3.0f, @0.0f] target:1.0f];  // x4

// One bias likes a net of neural network
[smo addBias:@0.0f];

// One input value by one weight that likes inputs & weights of neural network
[smo addWeights:@[@0.0f, @0.0f]];

[smo classifyWithPerIteration:^(NSInteger iteration, NSArray *weights, NSArray *biases) {
    //NSLog(@"%li Iteration weights : %@", iteration, weights);
    //NSLog(@"%li Iteration biases : %@", iteration, biases);
} completion:^(BOOL success, NSArray *weights, NSArray *biases, NSDictionary *groups, NSInteger totalIterations) {
    NSLog(@"%li Completion weights : %@", totalIterations, weights);
    NSLog(@"%li Completion biases : %@", totalIterations, biases);
    NSLog(@"%li Completion groups : %@", totalIterations, groups);
    // Verify & Directly Output
    [smo classifyPatterns:@[@[@2.0f, @2.0f], @[@3.0f, @0.0f]] completion:^(NSArray *weights, NSArray *biases, NSArray *results, NSDictionary *allGroups) {
        for( KRSVMPattern *pattern in results )
            NSLog(@"direct classify to target %@", pattern.classifiedTarget);
        NSLog(@"all groups : %@", allGroups);





Latest podspec

    "name": "KRSVM",
    "version": "1.0.0",
    "summary": "KRSVM is implemented SVM of machine learning.",
    "description": "KRSVM is implemented Support Vector Machine (SVM) of machine learning, it current achieved SMO and RBF, Tangent, Linear these 3 kernel functions to do predication.",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "Kalvar Lin": "[email protected]"
    "social_media_url": "",
    "source": {
        "git": "",
        "tag": "1.0.0"
    "platforms": {
        "ios": "7.0"
    "requires_arc": true,
    "public_header_files": "SVM/**/*.h",
    "source_files": "SVM/**/*.{h,m}",
    "frameworks": "Foundation"

Pin It on Pinterest

Share This