import pandas
from sklearn.cross_validation import cross_val_score
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.svm import LinearSVC

input_filename = "../data/spam/SMSSpamCollection"
input_file = open(input_filename)

labels = []
messages = []

for line in input_file.readlines():
    words = line.split("\t")
    labels.append(words[0])
    messages.append(words[1])

tf_transformer = TfidfVectorizer()
X = tf_transformer.fit_transform(messages)
y = pandas.get_dummies(labels, drop_first=True).values.ravel()

learner = LinearSVC()
scores = cross_val_score(learner, X, y, cv=5, scoring="accuracy")
print(scores.mean())
scores = cross_val_score(learner, X, y, cv=5, scoring="recall")
print(scores.mean())
scores = cross_val_score(learner, X, y, cv=5, scoring="precision")
print(scores.mean())

@@ -11,409 +11,191 @@
 das%0A
-from sklearn.cross_validation import cross_val_score%0Afrom sklearn.feature_extraction.text import TfidfVectorizer%0Afrom sklearn.svm import LinearSVC%0A%0Ainput_filename = %22../data/spam/SMSSpamCollection%22%0Ainput_file = open(input_filename)%0A%0Alabels = %5B%5D%0Amessages = %5B%5D%0A%0Afor line in input_file.readlines():%0A    words = line.split(%22%5Ct%22)%0A    labels.append(words%5B0%5D)%0A    messages.append(words%5B1%5D)%0A%0Atf_transformer = 
+import sklearn, sklearn.feature_extraction, sklearn.svm%0A%0Adf = pandas.read_csv(%22../data/spam/SMSSpamCollection%22, sep=%22%5Ct%22, header=-1)%0A%0Atf_transformer = sklearn.feature_extraction.text.
 Tfid
@@ -245,16 +245,13 @@
 orm(
-messages
+df%5B1%5D
 )%0Ay 
@@ -275,14 +275,13 @@
 ies(
-labels
+df%5B0%5D
 , dr
@@ -321,16 +321,28 @@
 arner = 
+sklearn.svm.
 LinearSV
@@ -346,32 +346,57 @@
 rSVC()%0Ascores = 
+sklearn.cross_validation.
 cross_val_score(
@@ -458,32 +458,57 @@
 ean())%0Ascores = 
+sklearn.cross_validation.
 cross_val_score(
@@ -576,16 +576,41 @@
 cores = 
+sklearn.cross_validation.
 cross_va

Compress a bit