Skip to content

Commit

Permalink
Remove duplicate code parts
Browse files Browse the repository at this point in the history
  • Loading branch information
Darius Morawiec committed Mar 23, 2017
1 parent 06ec7ab commit 70f2fc7
Showing 1 changed file with 6 additions and 30 deletions.
36 changes: 6 additions & 30 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,37 +187,21 @@ The exported [result](examples/classifier/DecisionTreeClassifier/java/basics.py#
Or run the prediction(s) in the target programming language directly:

```python
from sklearn.datasets import load_iris
from sklearn.tree import tree
from sklearn_porter import Porter

# Load data and train the classifier:
iris_data = load_iris()
X, y = iris_data.data, iris_data.target
clf = tree.DecisionTreeClassifier()
clf.fit(X, y)
# ...

# Prediction(s):
porter = Porter(clf, language='java')
preds = porter.predict(X)
pred = porter.predict(X[0])
pred = porter.predict([1., 2., 3., 4.])
Y_preds = porter.predict(X)
y_pred = porter.predict(X[0])
y_pred = porter.predict([1., 2., 3., 4.])
```

### Accuracy

Test the accuracy between the original and the ported estimator:

```python
from sklearn.datasets import load_iris
from sklearn.tree import tree
from sklearn_porter import Porter

# Load data and train the classifier:
iris_data = load_iris()
X, y = iris_data.data, iris_data.target
clf = tree.DecisionTreeClassifier()
clf.fit(X, y)
# ...

# Accuracy:
porter = Porter(clf, language='java')
Expand All @@ -230,15 +214,7 @@ print(accuracy) # 1.0
This example shows how you can port a model from the command line. First of all you have to store the model to the [pickle format](http://scikit-learn.org/stable/modules/model_persistence.html#persistence-example):

```python
from sklearn.datasets import load_iris
from sklearn.tree import tree
from sklearn.externals import joblib

# Load data and train the classifier:
iris_data = load_iris()
X, y = iris_data.data, iris_data.target
clf = tree.DecisionTreeClassifier()
clf.fit(X, y)
# ...

# Extract estimator:
joblib.dump(clf, 'model.pkl')
Expand Down

0 comments on commit 70f2fc7

Please sign in to comment.