Mercurial > hg > from-my-pen-to-your-ears-supplementary-material
view demo/rel.py @ 1:eb3b846ae0ef tip
second commit
author | Emmanouil Theofanis Chourdakis <e.t.chourdakis@qmul.ac.uk> |
---|---|
date | Wed, 16 May 2018 18:13:41 +0100 |
parents | 4dad87badb0c |
children |
line wrap: on
line source
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Apr 30 17:49:36 2018 @author: Emmanouil Theofanis Chourdakis """ from sklearn.svm import LinearSVC from sklearn.feature_extraction import DictVectorizer class RelModel(LinearSVC): ## TODO: Add more LinearSVC parameters here def __init__(self): super(RelModel, self).__init__() self.dv = DictVectorizer() def fit(self, X, y, sample_weight=None): # Transform data and save transformer x = self.dv.fit_transform(X) return super(RelModel, self).fit(x, y, sample_weight) def predict(self, X): # Transform data with transformer x = self.dv.transform(X) return super(RelModel, self).predict(x)