Skip to content

Commit

Permalink
Merge 8f3e657 into d73048e
Browse files Browse the repository at this point in the history
  • Loading branch information
StrikerRUS committed May 5, 2020
2 parents d73048e + 8f3e657 commit 1e990cf
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 118 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -82,13 +82,13 @@ The output is consistent with the output of the `predict_proba` method of `Decis
Here's a simple example of how a linear model trained in Python environment can be represented in Java code:
```python
from sklearn.datasets import load_boston
from sklearn import linear_model
from sklearn.linear_model import LinearRegression
import m2cgen as m2c

boston = load_boston()
X, y = boston.data, boston.target

estimator = linear_model.LinearRegression()
estimator = LinearRegression()
estimator.fit(X, y)

code = m2c.export_to_java(estimator)
Expand Down
9 changes: 4 additions & 5 deletions tests/assemblers/test_ensemble.py
@@ -1,11 +1,11 @@
from sklearn import ensemble
from sklearn.ensemble import RandomForestRegressor, RandomForestClassifier

from m2cgen import assemblers, ast
from tests import utils


def test_single_condition():
estimator = ensemble.RandomForestRegressor(n_estimators=2, random_state=1)
estimator = RandomForestRegressor(n_estimators=2, random_state=1)

estimator.fit([[1], [2]], [1, 2])

Expand All @@ -30,7 +30,7 @@ def test_single_condition():


def test_two_conditions():
estimator = ensemble.RandomForestRegressor(n_estimators=2, random_state=13)
estimator = RandomForestRegressor(n_estimators=2, random_state=13)

estimator.fit([[1], [2], [3]], [1, 2, 3])

Expand Down Expand Up @@ -61,8 +61,7 @@ def test_two_conditions():


def test_multi_class():
estimator = ensemble.RandomForestClassifier(
n_estimators=2, random_state=13)
estimator = RandomForestClassifier(n_estimators=2, random_state=13)

estimator.fit([[1], [2], [3]], [1, -1, 1])

Expand Down
15 changes: 8 additions & 7 deletions tests/assemblers/test_linear.py
Expand Up @@ -4,7 +4,8 @@
from statsmodels.regression.process_regression import ProcessMLE
from lightning.regression import AdaGradRegressor
from lightning.classification import AdaGradClassifier
from sklearn import linear_model
from sklearn.linear_model import \
LinearRegression, LogisticRegression, RANSACRegressor
from sklearn.dummy import DummyRegressor
from sklearn.tree import DecisionTreeRegressor

Expand All @@ -13,7 +14,7 @@


def test_single_feature():
estimator = linear_model.LinearRegression()
estimator = LinearRegression()
estimator.coef_ = np.array([1])
estimator.intercept_ = np.array([3])

Expand All @@ -32,7 +33,7 @@ def test_single_feature():


def test_two_features():
estimator = linear_model.LinearRegression()
estimator = LinearRegression()
estimator.coef_ = np.array([1, 2])
estimator.intercept_ = np.array([3])

Expand All @@ -57,7 +58,7 @@ def test_two_features():


def test_multi_class():
estimator = linear_model.LogisticRegression()
estimator = LogisticRegression()
estimator.coef_ = np.array([[1, 2], [3, 4], [5, 6]])
estimator.intercept_ = np.array([7, 8, 9])

Expand Down Expand Up @@ -109,7 +110,7 @@ def test_multi_class():


def test_binary_class():
estimator = linear_model.LogisticRegression()
estimator = LogisticRegression()
estimator.coef_ = np.array([[1, 2]])
estimator.intercept_ = np.array([3])

Expand All @@ -135,7 +136,7 @@ def test_binary_class():

def test_ransac_custom_base_estimator():
base_estimator = DecisionTreeRegressor()
estimator = linear_model.RANSACRegressor(
estimator = RANSACRegressor(
base_estimator=base_estimator,
random_state=1)
estimator.fit([[1], [2], [3]], [1, 2, 3])
Expand All @@ -157,7 +158,7 @@ def test_ransac_custom_base_estimator():
@pytest.mark.xfail(raises=NotImplementedError, strict=True)
def test_ransac_unknown_base_estimator():
base_estimator = DummyRegressor()
estimator = linear_model.RANSACRegressor(
estimator = RANSACRegressor(
base_estimator=base_estimator,
random_state=1)
estimator.fit([[1], [2], [3]], [1, 2, 3])
Expand Down
14 changes: 7 additions & 7 deletions tests/assemblers/test_svm.py
@@ -1,13 +1,13 @@
import pytest
import numpy as np
from sklearn import svm
from sklearn.svm import SVC
from lightning.classification import KernelSVC
from m2cgen import assemblers, ast
from tests import utils


def test_rbf_kernel():
estimator = svm.SVC(kernel="rbf", random_state=1, gamma=2.0)
estimator = SVC(kernel="rbf", random_state=1, gamma=2.0)

estimator.fit([[1], [2]], [1, 2])

Expand All @@ -22,7 +22,7 @@ def test_rbf_kernel():


def test_linear_kernel():
estimator = svm.SVC(kernel="linear", random_state=1)
estimator = SVC(kernel="linear", random_state=1)

estimator.fit([[1], [2]], [1, 2])

Expand All @@ -43,7 +43,7 @@ def kernel_ast(sup_vec_value):


def test_sigmoid_kernel():
estimator = svm.SVC(kernel="sigmoid", random_state=1, gamma=2.0)
estimator = SVC(kernel="sigmoid", random_state=1, gamma=2.0)

estimator.fit([[1], [2]], [1, 2])

Expand Down Expand Up @@ -71,7 +71,7 @@ def kernel_ast(sup_vec_value):


def test_poly_kernel():
estimator = svm.SVC(kernel="poly", random_state=1, gamma=2.0, degree=2)
estimator = SVC(kernel="poly", random_state=1, gamma=2.0, degree=2)

estimator.fit([[1], [2]], [1, 2])

Expand Down Expand Up @@ -137,7 +137,7 @@ def kernel_ast(sup_vec_value):

@pytest.mark.xfail(raises=ValueError, strict=True)
def test_unknown_kernel():
estimator = svm.SVC(kernel=lambda x, y: np.transpose(x) * y)
estimator = SVC(kernel=lambda x, y: np.transpose(x) * y)

estimator.fit([[1], [2]], [1, 2])

Expand All @@ -146,7 +146,7 @@ def test_unknown_kernel():


def test_multi_class_rbf_kernel():
estimator = svm.SVC(kernel="rbf", random_state=1, gamma=2.0)
estimator = SVC(kernel="rbf", random_state=1, gamma=2.0)

estimator.fit([[1], [2], [3]], [1, 2, 3])

Expand Down
8 changes: 4 additions & 4 deletions tests/assemblers/test_tree.py
@@ -1,11 +1,11 @@
from sklearn import tree
from sklearn.tree import DecisionTreeRegressor, DecisionTreeClassifier

from m2cgen import assemblers, ast
from tests import utils


def test_single_condition():
estimator = tree.DecisionTreeRegressor()
estimator = DecisionTreeRegressor()

estimator.fit([[1], [2]], [1, 2])

Expand All @@ -24,7 +24,7 @@ def test_single_condition():


def test_two_conditions():
estimator = tree.DecisionTreeRegressor()
estimator = DecisionTreeRegressor()

estimator.fit([[1], [2], [3]], [1, 2, 3])

Expand All @@ -49,7 +49,7 @@ def test_two_conditions():


def test_multi_class():
estimator = tree.DecisionTreeClassifier()
estimator = DecisionTreeClassifier()

estimator.fit([[1], [2], [3]], [0, 1, 2])

Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/test_cli.py
Expand Up @@ -3,7 +3,7 @@
import platform
import subprocess

from sklearn import linear_model
from sklearn.linear_model import LinearRegression

from tests import utils

Expand All @@ -22,7 +22,7 @@ def execute_test(exec_args):
def _prepare_pickled_model(tmp_path):
p = tmp_path / "model.pickle"

estimator = linear_model.LinearRegression()
estimator = LinearRegression()
utils.get_regression_model_trainer()(estimator)

p.write_bytes(pickle.dumps(estimator))
Expand Down

0 comments on commit 1e990cf

Please sign in to comment.