Lecture 11 Machine Learning Topics Basics of ML
Lecture 11: Machine Learning Topics: Basics of ML, Using Java ML in Android
Application Papers We Studied • All use some form of machine learning: Musical Heart Selection Sound Sifter Preprocess ing Feature Extraction Auditeur Classificatio n
What is Machine Learning? • The ability of computers to learn rules from data. X 1 A Math Equation That We Don’t Know X 2 Y
What is Machine Learning? • The ability of computers to learn rules from data. X 1 X 2 Y 3 4 12 5 2 10 10 3 30 X 1 A Math Equation That We Don’t Know X 2 Can you guess the function given the input-output data? Answer: Y = X 1 * X 2 Y
What is Machine Learning? • The ability of computers to learn rules from data. X 1 X 2 Y 10 2 12 5 2 7 8 2 10 X 1 A Math Equation That We Don’t Know X 2 Can you guess the function now? Answer: Y = X 1 + X 2 Y
What is Machine Learning? • The ability of computers to learn rules from data. X 1 X 2 Y 10 2 12 5 2 7 8 2 10 5 3 6 X 1 A Math Equation That We Don’t Know X 2 Can you guess the function now? Answer: Y = X 1 - X 2 + 4 Y
What is Machine Learning? • Often in machine learning, the output is +1 or -1. We may want to call it a “Classification” problem X 1 X 2 Y 170 137 +1 165 145 +1 120 2000 -1 127 2200 -1 X 1 A Function/Mapping That We Don’t Know X 2 Y
What is Machine Learning? • Often in machine learning, the output is +1 or -1. We may want to call it a “Classification” problem X 1 X 2 Y 170 137 +1 165 145 +1 120 2000 -1 127 2200 -1 X 1 A Function/Mapping That We Don’t Know Y X 2 if (X 1 <= 127 && X 2 >= 2000) { Y = -1; } else if (X 1 <= 170 && X 2 <= 145){ Y = +1; }
What is Machine Learning? • A real classification problem: Man vs. Cow Height X 1 (cm) Weight X 2 (lb) Class 170 137 Human 165 145 Human 120 2000 Cow 127 2200 Cow if (X 1 <= 127 && X 2 >= 2000) { Y = -1; //Cow } else if (X 1 <= 170 && X 2 <= 145){ Y = +1; //Man } Why do we want to learn these rules?
What is Machine Learning? • Learning/Training Phase: Height X 1 (cm) Weight X 2 (lb) Class 170 137 Human 165 145 Human 120 2000 Cow 127 2200 Cow • Applying/Testing Phase: Height X 1 (cm) Weight X 2 (lb) Class 120 2300 ? 160 100 ? if (X 1 <= 127 && X 2 >= 2000) { Y = -1; //Cow } else if (X 1 <= 170 && X 2 <= 145){ Y = +1; //Man }
What is Machine Learning? • Learning/Training Phase: Class Label features Instance X 1 X 2 … XN Y Model Training Set • Applying/Testing Phase: X 1 X 2 … Test Set XN Y
Machine Learning with Android • We will download and use Java. ML library http: //java-ml. sourceforge. net/ • To setup the library in Android Studio: https: //stackoverflow. com/questions/25660166/how-to-add-a-jar-in-externallibraries-in-android-studio Add your jar file to app/libs (if there is no libs folder you can create it) folder, and then right click the jar file and click "add as library“
Creating a Dataset (e. g. for training) • Create Instances: double row 1 row 2 row 3 row 4 Instance = = new new example 1 double[] = = new new {170. 0, {165. 0, {120. 0, {127. 0, 137. 0}; 145. 0}; 2000. 0}; 2200. 0}; Dense. Instance • Add Instances to Dataset: Dataset dset = new Default. Dataset(); dset. add(example 1); dset. add(example 2); dset. add(example 3); dset. add(example 4); (row 1, (row 2, (row 3, (row 4, ”human”); ”cow”);
Creating a Classifier (model) • Creating a classifier: Classifier knn = KNearest. Neighbors(3); knn. build. Classifier(dset); • Add Instances to Dataset: double unknown = new double[] {120. 0, 2300. 0}; Instance unknown_example = new Instance(unknown); Object result = knn. classify(unknown_example);
References • Study the API documentation of Java. ML (Getting Started and Classification PDFs)
- Slides: 15