Skip to content

Commit

Permalink
dummy test for svm
Browse files Browse the repository at this point in the history
  • Loading branch information
Lia committed Apr 16, 2018
1 parent 21006d8 commit e688cf7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ python src/hogwild/coordinator.py
#### Run tests
```bash
source activate hogwild-python
py.test --color=yes
py.test --color=yes -v
```
2 changes: 1 addition & 1 deletion src/hogwild/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
test_percentage = 0.1
epochs = 100
batch_size = 100
lambda_reg=1e-5
lambda_reg = 1e-5
2 changes: 1 addition & 1 deletion src/hogwild/svm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from utils import dotproduct, sign
from hogwild.utils import dotproduct, sign


class SVM:
Expand Down
32 changes: 32 additions & 0 deletions tests/test_svm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from hogwild.svm import SVM

mock_data = [{1: 0.1, 2: 0.2},
{1: 0.2, 4: 0.9},
{3: 0.9, 8: 1},
{4: 0.4, 5: 0.7}]
mock_labels = [1, -1, 1, -1]

mock_delta_w = {1: 0.01, 2: 0.02, 3: 0.03, 4: 0.04, 5: 0.05, 6: 0, 7: 0, 8: 0.08}


def test_fit():
svm = SVM(1, 1e-5, 9)
expected_result = {1: -0.100001,
2: 0.2,
3: 0.9,
4: -1.29999199999,
5: -0.6999909999899999,
8: 1.0}

result = svm.fit(mock_data, mock_labels)

assert expected_result == result


def test_predict():
svm = SVM(1, 1e-5, 9)
svm.fit(mock_data, mock_labels)
expected_result = [1]
result = svm.predict([{2: 0.8, 3: 0.9}])

assert expected_result == result

0 comments on commit e688cf7

Please sign in to comment.