Skip to content

Commit

Permalink
Add test for using optimizers
Browse files Browse the repository at this point in the history
  • Loading branch information
Darius Morawiec committed Aug 26, 2017
1 parent b444da7 commit f8b35e2
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/classifier/LinearSVC/LinearSVCJavaTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@

from unittest import TestCase

from sklearn.datasets import load_digits
from sklearn.decomposition import PCA, NMF
from sklearn.feature_selection import SelectKBest
from sklearn.feature_selection import chi2
from sklearn.model_selection import GridSearchCV
from sklearn.pipeline import Pipeline
from sklearn.svm.classes import LinearSVC

from sklearn_porter import Porter
from ..Classifier import Classifier
from ...language.Java import Java

Expand All @@ -16,3 +23,33 @@ def setUp(self):

def tearDown(self):
super(LinearSVCJavaTest, self).tearDown()

def test_model_within_optimizer(self):
pipe = Pipeline([
('reduce_dim', PCA()),
('classify', LinearSVC())
])
n_features_options = [2, 4, 8]
c_options = [1, 10, 100, 1000]
param_grid = [
{
'reduce_dim': [PCA(iterated_power=7), NMF()],
'reduce_dim__n_components': n_features_options,
'classify__C': c_options
},
{
'reduce_dim': [SelectKBest(chi2)],
'reduce_dim__k': n_features_options,
'classify__C': c_options
},
]
grid = GridSearchCV(pipe, cv=3, n_jobs=1, param_grid=param_grid)
digits = load_digits()
grid.fit(digits.data, digits.target)

try:
Porter(grid, language='java')
except ValueError:
self.assertTrue(False)
else:
self.assertTrue(True)

0 comments on commit f8b35e2

Please sign in to comment.