# Learners should have the following functions: # * a train function which takes in training data as a list of tuples: # [(instance_1, label_1), (instance_2, label_2), (instance_3, label_3)] # * a...

This is for a introductory machine learning course. Details of the assignment are contained in the word document.


# Learners should have the following functions: # * a train function which takes in training data as a list of tuples: # [(instance_1, label_1), (instance_2, label_2), (instance_3, label_3)] # * a classify function which takes in an instance and outputs a label, # or None if it is unable to produce a label. # # Labels are most often strings. # # The format for instances is a dict, mapping feature names # to feature values. # Here are some helper functions. # You are not required to use them, but they help with the fact # that instances (being themselves mutable dicts) cannot be # keys of other dicts (since keys of dicts must be immutable) # The functions turn the instance into something that can be used # as a key, and back again. def instanceToKey(instance): return frozenset(instance.items()) def keyToInstance(key): fDict = {} #This is the instance for (fName, fVal) in key: fDict[fName] = fVal return fDict #Simple learner that returns the most common label in the trainingData class MostCommonLabelLearner: # trains the learner with trainingData, which is a list of tuples as # described at the top of this file. # Hint: if you need to store variables that can be used later in training, # use self.variableName # Hint 2: self.mostCommonLabel is all you need to store for this one. def train(self, trainingData): #dict mapping labels to their counts labelCounts = {} for instance, label in trainingData: #TODO: increment the count of the relevant label (plz use .get()!) pass maxLabel = None maxCount = None for label in labelCounts: # TODO: fill in the rest pass #TODO: store off max pass def classify(self, instance): #TODO: Fill this in (should be just one line) pass # Simple learner that checks to see if the exact same instance was found in the # trainingData. If it was, it classifies it with the associated training label, # else it returns None # Note: You should use dicts to make classification fast. # The dict key should be the instance (call instanceToKey on it first!) and the value # should be the label. Don't worry about duplicate instances. class MemorizationLearner: # Trains the learner with trainingData, which is a list of tuples as # described at the top of this file. # Hint: if you need to store variables that can be used later in training, # use self.variableName # Hint 2: The easiest way is to make use of instanceToKey def train(self, trainingData): #TODO: Fill this in (should be just a few lines) pass def classify(self, instance): #TODO: Fill this in (should be as little as one line) pass artist,song,duration (seconds),loudness,beats-per-minute,end-of-fade-in (sec),start_of_fade_out (sec),familiarity,buzz,terms Casual,I Didn't Mean To,218.93179,-11.197,92.198,0.247,218.932,0.581793766,0.401997543,hip hop The Box Tops,Soul Deep,148.03546,-9.843,121.274,0.148,137.915,0.630630038,0.417499645,blue-eyed soul Sonora Santanera,Amor De Cabaret,177.47546,-9.689,100.07,0.282,172.304,0.487356791,0.343428378,salsa Adam Ant,Something Girls,233.40363,-9.013,119.293,0,217.124,0.630382334,0.454231157,pop rock Gob,Face the Ashes,209.60608,-4.501,129.738,0.066,198.699,0.651045661,0.401723686,pop punk Jeff And Sheri Easter,The Moon And I (Ordinary Day Album Version),267.7024,-9.323,147.782,2.264,254.27,0.535292736,0.385470551,southern gospel Rated R,Keepin It Real (Skit),114.78159,-17.302,111.787,0.096,114.782,0.556495602,0.261941177,breakbeat Tweeterfriendly Music,Drop of Rain,189.57016,-11.642,101.43,0.319,181.023,0.801136447,0.605507136,post-hardcore Planet P Project,Pink World,269.81832,-13.496,86.643,5.3,258.99,0.426667857,0.332275747,new wave Clp,Insatiable (Instrumental Version),266.39628,-6.697,114.041,0.084,261.747,0.550513698,0.422705641,breakcore JennyAnyKind,Young Boy Blues,218.77506,-10.021,146.765,2.125,207.012,0.360031167,0.296268954,alternative rock Wayne Watson,The Urgency (LP Version),245.21098,-7.545,117.975,0.357,227.48,0.545159296,0.351555861,ccm Andy Andy,La Culpa,226.35057,-6.632,130.04,0,221.553,0.577508974,0.37948217,bachata Bob Azzam,Auguri Cha Cha,191.84281,-7.75,137.334,0.38,188.424,0.085512047,0.251936525,chanson Lionel Richie,Tonight Will Be Alright,307.3824,-8.346,125.197,0.612,296.658,0.776675856,0.553071992,quiet storm Blue Rodeo,Floating,491.12771,-8.576,119.826,0,486.034,0.636423645,0.447935481,country rock Richard Souther,High Tide,228.5971,-16.11,127.756,0.223,217.426,0.419943148,0.330806357,chill-out Faiz Ali Faiz,Sohna Nee Sohna Data,599.24853,-8.032,99.273,1.193,591.999,0.363280571,0.306676094,qawwali Tesla,Caught In A Dream,290.29832,-5.271,150.062,0.145,285.605,0.707199764,0.51346329,hard rock lextrical,Synthetic Dream,165.69424,-6.787,138.331,0.162,157.391,0.32031437,0,indietronica Jimmy Wakely,Broken-Down Merry-Go-Round,151.84934,-15.221,86.186,2.827,146.199,0.39413854,0.291539727,classic country Alice Stuart,Kassie Jones,220.78649,-8.514,110.382,0.206,207.656,0.489816269,0.328553015,electric blues Elena,Setanta matins,269.58322,-8.05,111.874,0,256.168,0.677420465,0.378254686,uk garage The Dillinger Escape Plan,Setting Fire to Sleeping Giants,207.77751,-4.264,166.862,0.061,204.696,0.839962768,0.541888972,math-core SUE THOMPSON,James (Hold The Ladder Steady),124.86485,-12.332,137.522,0,115.74,0.435415818,0.306242264,pop rock Five Bolt Main,Made Like This (Live),225.09669,-5.908,164.672,0,225.097,0.6090637,0.363651365,post-grunge Clp,Superconfidential,338.31138,-6.486,125.006,0,338.311,0.550513698,0.422705641,breakcore Tim Wilson,I Think My Wife Is Running Around On Me (Taco Hell),186.48771,-4.516,90.022,1.083,175.467,0.459797129,0.349912612,filk Willie Bobo,Spanish Grease,168.25424,-9.616,127.025,0.2,161.89,0.588827101,0.379671125,latin jazz Faye Adams,Crazy Mixed Up World,156.39465,-18.051,95.957,0.562,150.634,0.396455254,0.299230368,jump blues Terry Callier,Do You Finally Need A Friend,342.56934,-11.939,110.189,0.063,333.154,0.706827671,0.416173065,soul jazz John Wesley,The Emperor Falls,484.62322,-15.335,138.007,28.172,480.363,0.560557984,0.452789477,disco The Shangri-Las,Twist and Shout,164.80608,-10.922,130.1,0,156.177,0.640807102,0.418216518,doo-wop Billie Jo Spears,It Makes No Difference Now,133.32853,-9.983,160.839,0,130.009,0.523714637,0.384611084,classic country Mike Jones (Featuring CJ_ Mello & Lil' Bran),Laws Patrolling (Album Version),173.66159,-7.762,41.993,0,164.908,0.79360508,0.426317956,rap Sierra Maestra,A?DA3nde va Chichi?,313.12934,-9.512,189.646,0,307.688,0.501544777,0.392733676,charanga Butthole Surfers,"Barking Dogs (From ""Piouhgd"")",450.84689,-9.063,130.586,0.467,426.104,0.809323793,0.488019842,noise rock Despina Vandi,OUTE ENA EFHARISTO,303.09832,-8.879,128.292,0.067,294.818,0.632559542,0.41168896,dance pop Javier Navarrete,Midnight Swim,128.83546,-17.699,90.932,0,121.423,0.597541218,0.382651971,orchestra Jacob Young,In A Subtle Way,456.30649,-19.478,89.667,0.241,451.315,0.495445922,0.294861262,cool jazz Scarlet's Remains,Spin,198.73914,-7.469,115.061,0,193.016,0.527865076,0.393121934,gothic metal The Suicide Machines,Burning In The Aftermath,95.68608,-2.022,115.887,0,87.806,0.668674533,0.467538444,ska punk The Rolling Stones,Angie (1993 Digital Remaster),271.49016,-10.358,139.333,0.171,263.784,0.814829656,0.735765693,blues Roberto Torres,Sabor Guajiro,226.66404,-12.716,117.271,0.311,219.51,0.482356043,0.350078579,salsa Loudon Wainwright III,Human Cannonball,190.48444,-15.663,102.428,0.258,177.029,0.661080168,0.442765842,modern rock R.L. Burnside,Glory Be,277.78567,-6.944,89.984,0.24,267.453,0.701180874,0.466628889,delta blues Stevie Ray Vaughan,Crossfire,248.78975,-7.805,116.721,0.183,246.19,0.73379894,0.544257506,texas blues John Hammond,I Can't Be Satisfied,195.3171,-10.7,123.142,0,187.617,0.590692918,0.452817838,blues Casiotone For The Painfully Alone,Nashville Parthenon,175.72526,-10.93,141.919,0.734,168.699,0.665322162,0.394217199,trip hop Ec8or,Cocain Ducks,217.23383,-9.493,95.596,1.042,213.496,0.50407567,0.33457736,hardcore techno The New York Dolls,Human Being,344.05832,-9.253,154.953,0.068,335.029,0.717670525,0.479308459,glam rock Eliane Elias,The More I See You,251.42812,-12.009,86.091,0.071,237.598,0.669726188,0.427914247,brazilian jazz Lost Boyz,Certain Things We Do,269.7922,-11.043,90.218,0.218,257.416,0.569741152,0.412240601,gangster rap The Germs,Forming,206.05342,-11.506,133.144,0,206.053,0.640048357,0.40439264,rock Yamandu Costa,MafuA!,190.04036,-14.179,205.317,0,176.924,0.397772876,0.383475745,brazilian jazz Chris Rea,Driving Home For Christmas,241.162,-8.531,180.149,0.549,230.342,0.643182773,0.500691341,soft rock Perrey And Kingsley,Spooks In Space,122.64444,-8.541,102.538,0.99,109.627,0.411421048,0.338414819,easy listening Eurythmics,Tous Les GarASSons Et Les Filles,207.0722,-6.629,84.164,2.583,202.757,0.75100762,0.523699078,dance rock Francis Dunnery,Too Much Saturn,300.79955,-13.33,124.175,0,298.347,0.54858513,0
Feb 06, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here