{"id":32955088,"url":"https://github.com/Kalvar/ios-KRKmeans-Algorithm","last_synced_at":"2025-11-13T06:01:06.613Z","repository":{"id":18253332,"uuid":"21407846","full_name":"Kalvar/ios-KRKmeans-Algorithm","owner":"Kalvar","description":"K-Means is clustering algorithm (クラスタリング分類) that one of Machine Learning methods.","archived":false,"fork":false,"pushed_at":"2016-06-10T08:19:13.000Z","size":438,"stargazers_count":23,"open_issues_count":1,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-10-10T12:35:25.795Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kalvar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-02T01:42:40.000Z","updated_at":"2020-08-09T04:25:39.000Z","dependencies_parsed_at":"2022-07-26T02:31:58.287Z","dependency_job_id":null,"html_url":"https://github.com/Kalvar/ios-KRKmeans-Algorithm","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/Kalvar/ios-KRKmeans-Algorithm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kalvar%2Fios-KRKmeans-Algorithm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kalvar%2Fios-KRKmeans-Algorithm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kalvar%2Fios-KRKmeans-Algorithm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kalvar%2Fios-KRKmeans-Algorithm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kalvar","download_url":"https://codeload.github.com/Kalvar/ios-KRKmeans-Algorithm/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kalvar%2Fios-KRKmeans-Algorithm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":283889554,"owners_count":26911915,"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","status":"online","status_checked_at":"2025-11-11T02:00:06.610Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-11-12T22:00:41.099Z","updated_at":"2025-11-13T06:01:06.605Z","avatar_url":"https://github.com/Kalvar.png","language":"Objective-C","funding_links":[],"categories":["Objective C"],"sub_categories":["General-Purpose Machine Learning"],"readme":"ios-KRKmeans-Algorithm\n=================\n\nKRKmeans has implemented K-Means the clustering algorithm (クラスタリング分類) and achieved multi-dimensional clustering in this project. KRKmeans could be used in data mining (データマイニング), image compression (画像圧縮) and classification.\n\n#### Podfile\n\n```ruby\nplatform :ios, '7.0'\npod \"KRKmeans\", \"~\u003e 2.6.1\"\n```\n\n## How to use\n\n#### Imports\n\n``` objective-c\n#import \"KRKmeans.h\"\n```\n\n#### Distance Methods\n\n``` objective-c\n\"KRKmeansKernelCosine\" is Cosine Similarity.\n\"KRKmeansKernelEuclidean\" is Euclidean.\n\"KRKmeansKernelRBF\" is Radial Basis Function.\n```\n\n#### Choosing Centers of Groups\n\n``` objective-c\n// 1. Random choosing the centers of groups from patterns.\n[kmeans randomChooseCenters:3];\n\n// 2. Quickly customizing the groups and centers\n[kmeans addGroupForCenterFeatures:@[@2, @2] centerId:@\"Center_1\" groupId:@\"Group_1\"];\n[kmeans addGroupForCenterFeatures:@[@6, @5] centerId:@\"Center_2\" groupId:@\"Group_2\"];\n[kmeans addGroupForCenterFeatures:@[@3, @17] centerId:@\"Center_3\" groupId:@\"Group_3\"];\n```\n\n#### One dimensonal clustering\n\nThe one dimensonal clustering.\n\n``` objective-c\n-(void)oneDemensionalClustering\n{\n    //One dimensional K-Means, the data set is any number means.\n    KRKmeansOne *kmeansOne = [KRKmeansOne sharedKmeans];\n    kmeansOne.sources      = @[@0.33, @0.88, @1, @0.52, @146, @120, @45, @43, @0.4];\n    \n    //If you wanna customize the median value\n    //kmeansOne.customMedian = 45.0f;\n    \n    [kmeansOne clusteringWithCompletion:^(BOOL success, float knowledgeLine, NSArray *maxClusters, NSArray *minClusters, NSArray *midClusters, NSDictionary *overlappings)\n    {\n        NSLog(@\"knowledgeLine : %f\", knowledgeLine);\n        NSLog(@\"maxClusters : %@\", maxClusters);\n        NSLog(@\"minClusters : %@\", minClusters);\n        NSLog(@\"midClusters : %@\", midClusters);\n        NSLog(@\"overlappings : %@\", overlappings);\n        //[_krKmeansOne printResults];\n    }];\n}\n\n```\n\n#### Multi-dimensonal clustering\n\n``` objective-c\n-(void)multiClustering\n{\n    KRKmeans *kmeans     = [KRKmeans sharedKmeans];\n    kmeans.modelKey      = @\"MyKmeans1\";\n    kmeans.saveAfterDone = YES;\n    kmeans.maxIteration  = 10;\n    \n    // Adding patterns\n    NSArray *patterns = @[@[@5, @4], @[@3, @4], @[@2, @5], @[@9, @8], @[@3, @20],\n                          @[@1, @1], @[@1, @2], @[@2, @2], @[@3, @2], @[@3, @1],\n                          @[@6, @4], @[@7, @6], @[@5, @6], @[@6, @5], @[@7, @8],\n                          @[@3, @12], @[@5, @20]];\n    NSInteger index   = -1;\n    for( NSArray *features in patterns )\n    {\n        index += 1;\n        NSString *patternId      = [NSString stringWithFormat:@\"Training_%li\", index];\n        KRKmeansPattern *pattern = [kmeans createPatternWithFeatures:features patternId:patternId];\n        [kmeans addPattern:pattern];\n    }\n    \n    [kmeans randomChooseCenters:3];\n    [kmeans setupKernel:KRKmeansKernelEuclidean];\n    [kmeans clusteringWithCompletion:^(BOOL success, KRKmeans *kmeansObject, NSInteger totalTimes) {\n        NSLog(@\"totalTimes : %li\", totalTimes);\n        NSLog(@\"featuresOfCenters : %@\", kmeansObject.featuresOfCenters);\n        NSLog(@\"centers objects: %@\", kmeansObject.centers);\n        NSLog(@\"SSE : %lf\", kmeansObject.sse);\n    } perIteration:^(NSInteger times, KRKmeans *kmeansObject, BOOL *pause) {\n        NSLog(@\"times : %li\", times);\n        // If you want to direct pause that next iteration running, then you could set :\n        //*pause = YES;\n    }];\n    \n}\n```\n\n#### Predicating \u0026 Recovering\n\nTo recover that trained model to predicate the patterns.\n\n``` objective-c\n// Recovering the tranined groups to predicate patterns.\n-(void)predicatingByTrainedModel\n{\n    KRKmeans *kmeans = [KRKmeans sharedKmeans];\n    [kmeans recoverGroupsForKey:@\"MyKmeans1\"];\n    \n    NSMutableArray *samples = [NSMutableArray new];\n    NSArray *patterns       = @[@[@21, @12], @[@13, @21], @[@12, @5], @[@3, @8]];\n    NSInteger index         = -1;\n    for( NSArray *features in patterns )\n    {\n        index += 1;\n        NSString *patternId      = [NSString stringWithFormat:@\"Predication_%li\", index];\n        KRKmeansPattern *pattern = [kmeans createPatternWithFeatures:features patternId:patternId];\n        [samples addObject:pattern];\n    }\n    \n    [kmeans predicatePatterns:samples completion:^(BOOL success, KRKmeans *kmeansObject, NSInteger totalTimes) {\n        NSLog(@\"\\n\\n====================== Predication ===========================\\n\\n\");\n        [kmeansObject printResults];\n    }];\n    \n}\n```\n\n## Version\n\nV2.6.1\n\n## License\n\nMIT.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKalvar%2Fios-KRKmeans-Algorithm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FKalvar%2Fios-KRKmeans-Algorithm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKalvar%2Fios-KRKmeans-Algorithm/lists"}