KRKNN 1.1.4

KRKNN 1.1.4

测试已测试
Lang语言 Obj-CObjective C
许可 MIT
发布最新发布2016年2月

Kalvar Lin维护。



KRKNN 1.1.4

ios-KRKNN

在本项目中实现机器学习(マシンラーニング),实现了KNN(k-Nearest Neighbor)分类方法。它可用于产品推荐(おすすめ的商品)、用户行为分析(ユーザーの行動分析)、数据挖掘(データマイニング)和数据分析(データ分析)。

Podfile

platform :ios, '7.0'
pod "KRKNN", "~> 1.1.4"

如何使用

导入KRKNN.h文件

#import "KRKNN.h"

通常示例

当前实现的核方法距离为

KRKNNKernelEuclidean
KRKNNKernelCosineSimilarity
KRKNNKernelRBF
KRKNN *_knn = [KRKNN sharedInstance];
// To use Cosine Simlarity or Euclidean that will have different results, suggests to use Cosine Similarity
_knn.kernel = KRKNNKernelEuclidean;

// Features are the wordings appeared times on a paper as below :
// Apple, OS, Mobile, Taiwan, Japan, Developer
[_knn addFeatures:@[@20, @9, @1, @3, @6, @2]
            group:@"Apple Fans"
       identifier:@"Smith"];

[_knn addFeatures:@[@52, @32, @18, @7, @0, @1]
            group:@"Apple Fans"
       identifier:@"John"];

[_knn addFeatures:@[@2, @20, @15, @5, @9, @16]
            group:@"Linux Fans"
       identifier:@"James"];

[_knn addFeatures:@[@7, @11, @2, @12, @1, @0]
            group:@"Linux Fans"
       identifier:@"Terry"];

[_knn addFeatures:@[@20, @8, @3, @21, @8, @25]
            group:@"Android Fans"
       identifier:@"Sam"];

[_knn addFeatures:@[@2, @30, @8, @6, @33, @29]
            group:@"Android Fans"
       identifier:@"Amy"];

// If you have batch-patterns (ex : 10 patterns) wanna classify that you could use for-loop to run the classify function,
// In this demo that classifies a pattern by once time.
[_knn classifyFeatures:@[@20, @1, @10, @2, @12, @3]
            identifier:@"Bob"
             kNeighbor:[_knn chooseK]
            completion:^(BOOL success, NSString *ownGroup, NSInteger neighborCount, NSArray *allPatterns) {
                if( success )
                {
                    NSLog(@"ownGroup : %@", ownGroup);
                    NSLog(@"neighborCount : %li", neighborCount);
                    NSLog(@"allPatterns : %@", allPatterns);
                    // Looping that all classified patterns.
                    for( KRKNNPattern *pattern in allPatterns )
                    {
                        NSLog(@"pattern id is 「%@」 and group name is 「%@", pattern.identifier, pattern.groupName);
                    }
                }
            }];

版本

V1.1.4

许可

MIT.