Mercurial > hg > from-my-pen-to-your-ears-supplementary-material
comparison demo/rel.py @ 0:4dad87badb0c
initial commit
author | Emmanouil Theofanis Chourdakis <e.t.chourdakis@qmul.ac.uk> |
---|---|
date | Wed, 16 May 2018 17:56:10 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4dad87badb0c |
---|---|
1 #!/usr/bin/env python3 | |
2 # -*- coding: utf-8 -*- | |
3 """ | |
4 Created on Mon Apr 30 17:49:36 2018 | |
5 | |
6 @author: Emmanouil Theofanis Chourdakis | |
7 """ | |
8 | |
9 from sklearn.svm import LinearSVC | |
10 from sklearn.feature_extraction import DictVectorizer | |
11 | |
12 class RelModel(LinearSVC): | |
13 ## TODO: Add more LinearSVC parameters here | |
14 def __init__(self): | |
15 super(RelModel, self).__init__() | |
16 self.dv = DictVectorizer() | |
17 | |
18 def fit(self, X, y, sample_weight=None): | |
19 | |
20 # Transform data and save transformer | |
21 x = self.dv.fit_transform(X) | |
22 | |
23 return super(RelModel, self).fit(x, y, sample_weight) | |
24 | |
25 def predict(self, X): | |
26 # Transform data with transformer | |
27 x = self.dv.transform(X) | |
28 | |
29 return super(RelModel, self).predict(x) |