@@ -0,0 +1,1286 @@
+#!/usr/bin/env python%0A# -*- coding: utf-8 -*-%0A# @Author: Zeyuan Shang%0A# @Date:   2016-01-13 16:08:21%0A# @Last Modified by:   Zeyuan Shang%0A# @Last Modified time: 2016-01-13 16:08:29%0Aimport json%0Aimport sys%0Afrom sklearn.feature_extraction.text import HashingVectorizer%0Afrom sklearn.svm import LinearSVC%0A%0Atransformer = HashingVectorizer(stop_words='english')%0A%0Adef read_train_data():%0A    f = open('training.json')%0A    n = int(f.readline())%0A    trainData = %5B%5D%0A    trainLabel = %5B%5D%0A    for _ in xrange(n):%0A        data = json.loads(f.readline())%0A        trainData.append(data%5B'question'%5D + '%5Cr%5Cn' + data%5B'excerpt'%5D)%0A        trainLabel.append(data%5B'topic'%5D)%0A    f.close()%0A    trainData = transformer.fit_transform(trainData)%0A    return trainData, trainLabel%0A%0Adef read_test_data():%0A    n = input()%0A    testData = %5B%5D%0A    for _ in xrange(n):%0A        data = json.loads(raw_input())%0A        testData.append(data%5B'question'%5D + '%5Cr%5Cn' + data%5B'excerpt'%5D)%0A    testData = transformer.fit_transform(testData)%0A    return testData%0A    %0Adef main():    %0A    trainData, trainLabel = read_train_data()%0A    svm = LinearSVC()%0A    svm.fit(trainData, trainLabel)%0A    testData = read_test_data()%0A    testLabel = svm.predict(testData)%0A    for e in testLabel: %0A        print(e)%0A    %0Aif __name__ == %22__main__%22:%0A    main()

add stack-exchange-question-classifier