Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

uestion 4 (PROGRAMMING A classification algorithm is a kind of machine learning algorithm which is used to assign a label to an object, based on

image text in transcribed

uestion 4 (PROGRAMMING A classification algorithm is a kind of machine learning algorithm which is used to assign a label to an object, based on the knowledge of similar objects. Write a C program able to implement the classification algorithm 1-NN The program receives as input two files , whose names are passed as arguments from the command line The file contains a set of N objects (one for each line), each one with the corresponding label. This file is used to train the classification algorithm, which learns how to recognize the known objects. Each line of the file contains the name of the object represented as a string at most 5 characters, a set of M real numbers Ti T2 T3 TM, followed by an integer L. The space character is used to separate the elements. The M real numbers are the features that represents an object. The integer L is the object label The file contains a set of objects to be classified. The format is similar to the file, but the number of rows is NOT KNOWN IN ADVANCE Assume that the values M and N are known in advance and are defined as symbolic constants by means of the#define directive The distance between two objects O and T is defined as follows Do-T--/2:1 (0,-T)2 where 0, and T, are the real numbers used to represents the objects The program shall predict the label of each object O contained in the file , according to the following rules Calculate the distance between the object O and every object T of the file . The label to be assigned to O is the one of the object T that is the nearest to O For each classification, the program shall print a message on the screen indicating the name of the object, the label that has been predicted for the object, and its actual label (as reported in the file Finally, the program shall print on screen the accuracy of the classification algorithm, which is calculated as the ratio between the number of labels predicted properly divided by the total number of classified objects Example: M-2 N-9 Test.txt Train.txt T1 1.3 3.8 1 T2 1.6 3.9 1 T3 1.5 3.7 1 T4 4.0 10 3 TS 4.1 11 3 T6 4.2 14 3 7 2.5 2.5 2 T8 2.3 24 2 T9 2.6 26 2 Distances 01-T1 1.30 Q1-T2 1.43 01-T3 1.22 01-T4 3.09 01-T5 3.13 01-T6 3.10 01-T7 1.20 Distances 02-T1 2.21 02-T2 1.90 02-T3 2.02 02-T4 3.04 02-T5 2.96 02-T6 2.69 02-T7 1.80 01 1.3 2.5 2 02 3.5 4 3 01-18 100 01 label2 0218 200 01-T9 1.30 (correct 02-T9 1.66 O2 label 2 wron C:l>classify.exe train.txt test.txt Object 01: predicted label 2 actual label 2 Object O2: predicted label 2 actual label 3 The accuracy is equal to 0.50

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Datacasting How To Stream Databases Over The Internet

Authors: Jessica Keyes

1st Edition

007034678X, 978-0070346789

More Books

Students also viewed these Databases questions