view demo/rel.py @ 0:90155bdd5dd6

first commit
author Emmanouil Theofanis Chourdakis <e.t.chourdakis@qmul.ac.uk>
date Wed, 16 May 2018 18:27:05 +0100
parents
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)