Editing JonathanChang
from sklearn.svm import SVC from mudd.datasets.EastDorm import easties import numpy as np class JChang(object): def __init__(self): self.greeting_classifier = SVC() def extract_features(self, data): return np.array(self.feature_extractor(d) for d in data) def feature_extractor(self, person): features = [] features.append(1 if person.is_third_floor() else 0) features.append(person.dorm.id()) features.append(person.year) features.append(1 if person.likes_hugs() else 0) features.append(1 if person.is_timesuck() else 0) features.append(person.num_years_known) features.append(person.major.id()) return np.array(features) def train_model(self, train_data, train_labels): self.greeting_classifier.fit(train_data, train_labels) def get_greeting(self, people_to_greet): return self.greeting_classifier.predict(people_to_greet) if __name__ == '__main__': jchang = JChang() train_people = [easties.KiraWyld, easties.LisaYin, easties.AdamDunlap, easties.IanSong, easties.SaraMcAllister] train_labels = np.array(['headpat', 'hug', 'headpat', 'hug', 'headpat']) train_data = jchang.extract_features(train_people) jchang.train(train_data, train_labels) people_to_greet = sys.argv[1] greetings = jchang.get_greeting(jchang.extract_features(people_to_greet)) for greeting in greetings: print(greeting)
Summary:
This change is a minor edit.
(Visit
Preferences
to set your user name.)