Skip to content

High-performance Cocoa framework for Machine Learning on iOS and OS X.

License

Notifications You must be signed in to change notification settings

almost-free/LearnKit

 
 

Repository files navigation

LearnKit

LearnKit is a Cocoa framework for Machine Learning. It currently runs on top of the Accelerate framework on iOS and OS X.

Supported Algorithms

  • Anomaly Detection
  • Collaborative Filtering
  • Decision Trees
  • k-Means
  • k-Nearest Neighbors
  • Linear Regression
  • Logistic Regression
  • Naive Bayes
  • Neural Networks
  • Principal Component Analysis
  • Support Vector Machines

Example

In this example, we have a matrix that contains 5000 20x20 digits. Each 20x20 digit has been flattened into a row of 400 pixel intensities. We load it as such:

NSURL *matrixURL = [NSURL fileURLWithPath:matrixPath];
NSURL *matrixOutputURL = [NSURL fileURLWithPath:outputVectorPath];

LNKMatrix *matrix = [[LNKMatrix alloc] initWithBinaryMatrixAtURL:matrixURL
												 matrixValueType:LNKValueTypeDouble
											   outputVectorAtURL:matrixOutputURL
										   outputVectorValueType:LNKValueTypeUInt8
														rowCount:5000
													 columnCount:400
												addingOnesColumn:YES];

Next, we set up a conjugate gradient optimization algorithm to train the neural network.

LNKOptimizationAlgorithmCG *algorithm = [[LNKOptimizationAlgorithmCG alloc] init];
algorithm.iterationCount = 400;

Now we initialize a neural network classifier with our matrix and optimization algorithm. We also indicate the possible outputs are digits ranging from 1 to 10.

LNKNeuralNetClassifier *classifier = [[LNKNeuralNetClassifier alloc] initWithMatrix:matrix 
																 implementationType:LNKImplementationTypeAccelerate
															  optimizationAlgorithm:algorithm
																			classes:[LNKClasses withRange:NSMakeRange(1, 10)]];
classifier.hiddenLayerCount = 1;
classifier.hiddenLayerUnitCount = 25;

The neural network parameters above were picked with performance in mind. They can be fine-tuned to increase the accuracy of the classifier. Finally, we train the neural network classifer and predict the class of a previously-unseen digit.

[classifier train];

LNKClass *someDigit = [classifier predictValueForFeatureVector:someImage length:someImageLength];

With the right parameters, classification accuracy rates of over 99% can be attained.

Future Tasks

  • Port to Metal and OpenCL

License

LearnKit is available under the MIT license.

Credits

LearnKit uses:

  • fmincg by Carl Edward Rasmussen
  • liblbfgs
  • Data prepared by Andrew Ng for Machine Learning

About

High-performance Cocoa framework for Machine Learning on iOS and OS X.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C 85.5%
  • C 11.9%
  • MATLAB 1.0%
  • C++ 0.8%
  • Swift 0.4%
  • HTML 0.2%
  • Other 0.2%