@@ -0,0 +1,1948 @@
+#These are the packages that I used:%0Aimport pandas as pd%0Aimport numpy as np%0Afrom sklearn.lda import LDA%0Aimport datetime%0A%0A#Step one getting the data:%0A#specify my working directory:%0Apath = %22C:%5Clocalmachine%5CBill%5C%7B%7D%22%0A#I put it in this way so that I could just add CSV files as they come in. %0Amyfiles = %5B%22transactions2014.csv%22,%0A%09%09%09%22transactions2015.csv%22%5D%0Aframes = %5Bpd.read_csv(path.format(x)) for x in myfiles%5D%0Adf = pd.concat(frames)%0A%0A#Some quick cleaning:%0Akeep_cats = %5B'Arts&Crafts', 'Coffee', 'Eating at Home', 'Eating out', 'Education', 'Gaming', 'Grocery',%0A       'Lunch', 'Moving', 'Music', 'Out for drinks', 'Out of town',%0A       'Technology', 'Transportation', 'Uncategorized'%5D%0Adf%5B'filters'%5D = df%5B'Category'%5D.apply(lambda x: x in keep_cats)%0Adf = df%5Bdf%5B'filters'%5D%5D%0Adf = df.dropna().reset_index(drop=True)%0A%0A#adding a day of the week:%0Adef get_day_of_week(x):%0A%09try:%0A%09%09mydate = datetime.datetime.strptime(x, '%25m/%25d/%25Y')%0A%09except:%0A%09%09#I was inconsistent with my datestrings%0A%09%09#Why didn't I just use ISO format!%0A%09%09mydate = datetime.datetime.strptime(x, '%25m/%25d/%25y')%0A%09return mydate.strftime('%25A')%0A%09%0Adf%5B'dayOfWeek'%5D = df%5B'Date of pull'%5D.apply(lambda x: get_day_of_week(x))%0A%0A#then I'm using the %22distance from saturday as a proxy for catagorical value%22%0Adef dist_from_sat(x):%0A%09myvalues = %7B'Friday' :1,%0A%09%09%09%09'Monday':2,%0A%09%09%09%09'Saturday':0, %0A%09%09%09%09'Sunday':1, %0A%09%09%09%09'Thursday':2,%0A%09%09%09%09'Tuesday':3,%0A%09%09%09%09'Wednesday':3%7D%0A%09return myvalues%5Bx%5D%0Adf%5B'distFromSat'%5D = df%5B'dayOfWeek'%5D.apply(lambda x: dist_from_sat(x))%0A%09%0A%09%0A#transform my data for the model:%0AX = df.loc%5B:,%5B'distFromSat','Hour','Amount'%5D%5D.values%0Ay = df.loc%5B:,'Category'%5D.values%0A%0A#now I can run my model:%0Aclf = LDA()%0Aclf.fit(X, y)%0A%0A#now see if my model has any validity:%0Adf%5B'predictions'%5D = clf.predict(X)%0Aaccuracy_of_model = len(df%5Bdf%5B'predictions'%5D == df%5B'Category'%5D%5D)/(len(df)*1.)%0Aaccuracy_of_random_guess = 1./len(np.unique(y))%0A%0Aprint(accuracy_of_model-accuracy_of_random_guess)%0A#0.212 over random isn't so bad :)%0A

Create Predictive_Modeling.py