JJ Husker Posted November 2, 2016 Share Posted November 2, 2016 Count me out I did Fortran at UNL using punch cards. Ha, me too. Remember those stacks of cards? Never did interest me. We used to play a poker game called Anaconda. Deal seven cards, pass 3 to your right, discard 2, put your 5 cards face down in order then roll them 1 at a time...betting every step of the way. Fun times. 1 Quote Link to comment
Moiraine Posted November 2, 2016 Author Share Posted November 2, 2016 I figured it out. Will post code later in case anyone (Bob Zoogs) is curious. 1 Quote Link to comment
Moiraine Posted November 3, 2016 Author Share Posted November 3, 2016 BAM!The blob after dct = {} (that stands for dictionary, dirty people) is the part I needed help with and then the rest I figured out from that. import nltk import pickle import pandas raw_data = { 'first_name': ['Bob', 'Teacher', 'Moiraine', 'Alastair', 'Knap', 'Matilda'], 'last_name': ['Zoogs', 'CD', 'Damodred', 'Damodred', 'Plc', 'Plc'], 'gender': ['Male','Male','Female','Male','Male','Female'] } df = pandas.DataFrame(raw_data, columns = ['first_name', 'last_name', 'gender']) last_name_dict = dict(iter(df.groupby("last_name"))) def gender_features(word): return {'first_letter': word[0], 'last_letter': word[-1] } dct = {} for last in df.last_name.unique(): dct[last] = [] for first,gender in zip(last_name_dict[last].first_name,last_name_dict[last].gender): dct[last].append((gender_features(first),gender)) # TRAIN in a loop traindct = {} class_dct = {} for last in df.last_name.unique(): traindct['train_set_%s' % last] = dct[last][0:] class_dct['Classif_%s'% last] = nltk.NaiveBayesClassifier.train(traindct['train_set_%s' % last]) # CLASSIFY Test: Classif_Zoogs.classify(gender_features('Rob')) >>> Male Classif_Damodred.classify(gender_features('Elaine')) >>> Female 3 Quote Link to comment
huKSer Posted November 4, 2016 Share Posted November 4, 2016 Isn't it great when you solve the puzzle and feel the accomplishment? Quote Link to comment
Moiraine Posted November 4, 2016 Author Share Posted November 4, 2016 Isn't it great when you solve the puzzle and feel the accomplishment? Indeed Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.