Jump to content


Anyone know Python or Anaconda?


Recommended Posts

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.

  • Fire 1
Link to comment

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
  • Fire 3
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.

Visit the Sports Illustrated Husker site



×
×
  • Create New...