Permalink
Browse files

Code for training a basic SVM.

  • Loading branch information...
1 parent 3daa694 commit 5cd5eca4bbf61ea5cb699a0a70d29b4566b79160 @julosaure committed Apr 2, 2013
Showing with 25 additions and 2 deletions.
  1. +2 −1 preprocessData.py
  2. +23 −1 trainClassifier.py
View
@@ -6,7 +6,8 @@
#----------------------------------------------------
# training data file in csv format
-trainData="./data/LoanStats.h100.csv"
+trainDataSmall="./data/LoanStats.h100.csv"
+trainData="./data/LoanStats.h1k.csv"
#trainData="./data/InFunding2StatsNew (1).csv"
#---------------------------------------------------
View
@@ -1,9 +1,31 @@
+import math
+from sklearn import svm
+from sklearn import cross_validation
+import preprocessData as ppd
+
MODEL_DIR="./model/"
+def trainSVM(trainData):
+ svc = svm.SVC(kernel='linear')
+ k_fold = cross_validation.StratifiedKFold(trainData["target"], n_folds=3)
+ scores = []
+
+ for train, test in k_fold:
+ print "Iteration %d" % len(scores)
+ svc.fit(trainData["data"][train], trainData["target"][train])
+ score = svc.score(trainData["data"][test], trainData["target"][test])
+ scores.append(score)
+ print score
+
+ avg = round(math.fsum(scores) / float(len(scores)), 4)
+ #print scores
+ print "Avg score: %.4f" % avg
+
def main():
- pass
+ trainData = ppd.preprocessData(ppd.trainDataSmall)
+ trainSVM(trainData)
if __name__ == "__main__":
main()

0 comments on commit 5cd5eca

Please sign in to comment.