How to combine docker and sklearn
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I am trying to to convert a trained scikit-learn classifier into a Docker container.
I found the sklearn2docker project on github, but it failed.
I generate the test.py
script from the following code:
from pandas import DataFrame
from sklearn.datasets import load_iris
from sklearn.tree import DecisionTreeClassifier
iris = load_iris()
input_df = DataFrame(data=iris['data'], columns=iris['feature_names'])
clf = DecisionTreeClassifier(max_depth=2)
clf.fit(input_df.values, iris['target'])
from sklearn2docker.constructor import Sklearn2Docker
s2d = Sklearn2Docker(
classifier=clf,
feature_names=iris['feature_names'],
class_names=iris['target_names'].tolist()
)
s2d.save(name="classifier", tag="iris")
python test.py
runs the script and generates a container.
An error occurrs when I used the following code to predict:
from os import system
system("docker run -d -p 5000:5000 classifier:iris && sleep 5")
from requests import post
from pandas import read_json
request = post("http://localhost:5000/predict_proba/split",
json=input_df.to_json(orient="split"))
result = read_json(request.content.decode(), orient="split")
print(result.head())
The error is as follows:
requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=5000): Max retries exceeded with url: /predict/split (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused',))
I also try to directly use the Dockerfile
and requirements.txt
from constructor.py
in the sklearn2docker directory to generate the container using app.py
in the sklearn2docker
directory, but wasn't successful.
enter image description here
docker scikit-learn
add a comment |
I am trying to to convert a trained scikit-learn classifier into a Docker container.
I found the sklearn2docker project on github, but it failed.
I generate the test.py
script from the following code:
from pandas import DataFrame
from sklearn.datasets import load_iris
from sklearn.tree import DecisionTreeClassifier
iris = load_iris()
input_df = DataFrame(data=iris['data'], columns=iris['feature_names'])
clf = DecisionTreeClassifier(max_depth=2)
clf.fit(input_df.values, iris['target'])
from sklearn2docker.constructor import Sklearn2Docker
s2d = Sklearn2Docker(
classifier=clf,
feature_names=iris['feature_names'],
class_names=iris['target_names'].tolist()
)
s2d.save(name="classifier", tag="iris")
python test.py
runs the script and generates a container.
An error occurrs when I used the following code to predict:
from os import system
system("docker run -d -p 5000:5000 classifier:iris && sleep 5")
from requests import post
from pandas import read_json
request = post("http://localhost:5000/predict_proba/split",
json=input_df.to_json(orient="split"))
result = read_json(request.content.decode(), orient="split")
print(result.head())
The error is as follows:
requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=5000): Max retries exceeded with url: /predict/split (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused',))
I also try to directly use the Dockerfile
and requirements.txt
from constructor.py
in the sklearn2docker directory to generate the container using app.py
in the sklearn2docker
directory, but wasn't successful.
enter image description here
docker scikit-learn
1
What do you mean by turning it into a docker container? You can always get a container with Python, add sklearn, add the pickled file, and that's a model available in a container.
– Matthieu Brucher
Jan 3 at 10:34
usedocker run -d -p 5000:5000 classifier:iris
in your command prompt or poweshell and then run the commanddocker ps
and show the results
– Hansika Madushan Weerasena
Jan 3 at 10:52
1
Does the container actually start? Are you running your script withsudo
or something else that has the appropriate system-level permission to launch a container? One of your first debugging steps here should be to remote thedocker run -d
option and make sure it's actually coming up successfully.
– David Maze
Jan 3 at 11:01
I use the ubuntu18.04 installed docker,When test.py is executed, the container has been successfully created.I took a picture of it up here.When I run the command:docker run -d -p 5000:5000 classifier:iris,I use docker container ls,You see that the container is not started, but when I delete the image, it prompts me that the image is being used by the container
– guiniao
Jan 3 at 11:56
add a comment |
I am trying to to convert a trained scikit-learn classifier into a Docker container.
I found the sklearn2docker project on github, but it failed.
I generate the test.py
script from the following code:
from pandas import DataFrame
from sklearn.datasets import load_iris
from sklearn.tree import DecisionTreeClassifier
iris = load_iris()
input_df = DataFrame(data=iris['data'], columns=iris['feature_names'])
clf = DecisionTreeClassifier(max_depth=2)
clf.fit(input_df.values, iris['target'])
from sklearn2docker.constructor import Sklearn2Docker
s2d = Sklearn2Docker(
classifier=clf,
feature_names=iris['feature_names'],
class_names=iris['target_names'].tolist()
)
s2d.save(name="classifier", tag="iris")
python test.py
runs the script and generates a container.
An error occurrs when I used the following code to predict:
from os import system
system("docker run -d -p 5000:5000 classifier:iris && sleep 5")
from requests import post
from pandas import read_json
request = post("http://localhost:5000/predict_proba/split",
json=input_df.to_json(orient="split"))
result = read_json(request.content.decode(), orient="split")
print(result.head())
The error is as follows:
requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=5000): Max retries exceeded with url: /predict/split (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused',))
I also try to directly use the Dockerfile
and requirements.txt
from constructor.py
in the sklearn2docker directory to generate the container using app.py
in the sklearn2docker
directory, but wasn't successful.
enter image description here
docker scikit-learn
I am trying to to convert a trained scikit-learn classifier into a Docker container.
I found the sklearn2docker project on github, but it failed.
I generate the test.py
script from the following code:
from pandas import DataFrame
from sklearn.datasets import load_iris
from sklearn.tree import DecisionTreeClassifier
iris = load_iris()
input_df = DataFrame(data=iris['data'], columns=iris['feature_names'])
clf = DecisionTreeClassifier(max_depth=2)
clf.fit(input_df.values, iris['target'])
from sklearn2docker.constructor import Sklearn2Docker
s2d = Sklearn2Docker(
classifier=clf,
feature_names=iris['feature_names'],
class_names=iris['target_names'].tolist()
)
s2d.save(name="classifier", tag="iris")
python test.py
runs the script and generates a container.
An error occurrs when I used the following code to predict:
from os import system
system("docker run -d -p 5000:5000 classifier:iris && sleep 5")
from requests import post
from pandas import read_json
request = post("http://localhost:5000/predict_proba/split",
json=input_df.to_json(orient="split"))
result = read_json(request.content.decode(), orient="split")
print(result.head())
The error is as follows:
requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=5000): Max retries exceeded with url: /predict/split (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused',))
I also try to directly use the Dockerfile
and requirements.txt
from constructor.py
in the sklearn2docker directory to generate the container using app.py
in the sklearn2docker
directory, but wasn't successful.
enter image description here
docker scikit-learn
docker scikit-learn
edited Jan 3 at 11:55
guiniao
asked Jan 3 at 10:29
guiniaoguiniao
184
184
1
What do you mean by turning it into a docker container? You can always get a container with Python, add sklearn, add the pickled file, and that's a model available in a container.
– Matthieu Brucher
Jan 3 at 10:34
usedocker run -d -p 5000:5000 classifier:iris
in your command prompt or poweshell and then run the commanddocker ps
and show the results
– Hansika Madushan Weerasena
Jan 3 at 10:52
1
Does the container actually start? Are you running your script withsudo
or something else that has the appropriate system-level permission to launch a container? One of your first debugging steps here should be to remote thedocker run -d
option and make sure it's actually coming up successfully.
– David Maze
Jan 3 at 11:01
I use the ubuntu18.04 installed docker,When test.py is executed, the container has been successfully created.I took a picture of it up here.When I run the command:docker run -d -p 5000:5000 classifier:iris,I use docker container ls,You see that the container is not started, but when I delete the image, it prompts me that the image is being used by the container
– guiniao
Jan 3 at 11:56
add a comment |
1
What do you mean by turning it into a docker container? You can always get a container with Python, add sklearn, add the pickled file, and that's a model available in a container.
– Matthieu Brucher
Jan 3 at 10:34
usedocker run -d -p 5000:5000 classifier:iris
in your command prompt or poweshell and then run the commanddocker ps
and show the results
– Hansika Madushan Weerasena
Jan 3 at 10:52
1
Does the container actually start? Are you running your script withsudo
or something else that has the appropriate system-level permission to launch a container? One of your first debugging steps here should be to remote thedocker run -d
option and make sure it's actually coming up successfully.
– David Maze
Jan 3 at 11:01
I use the ubuntu18.04 installed docker,When test.py is executed, the container has been successfully created.I took a picture of it up here.When I run the command:docker run -d -p 5000:5000 classifier:iris,I use docker container ls,You see that the container is not started, but when I delete the image, it prompts me that the image is being used by the container
– guiniao
Jan 3 at 11:56
1
1
What do you mean by turning it into a docker container? You can always get a container with Python, add sklearn, add the pickled file, and that's a model available in a container.
– Matthieu Brucher
Jan 3 at 10:34
What do you mean by turning it into a docker container? You can always get a container with Python, add sklearn, add the pickled file, and that's a model available in a container.
– Matthieu Brucher
Jan 3 at 10:34
use
docker run -d -p 5000:5000 classifier:iris
in your command prompt or poweshell and then run the command docker ps
and show the results– Hansika Madushan Weerasena
Jan 3 at 10:52
use
docker run -d -p 5000:5000 classifier:iris
in your command prompt or poweshell and then run the command docker ps
and show the results– Hansika Madushan Weerasena
Jan 3 at 10:52
1
1
Does the container actually start? Are you running your script with
sudo
or something else that has the appropriate system-level permission to launch a container? One of your first debugging steps here should be to remote the docker run -d
option and make sure it's actually coming up successfully.– David Maze
Jan 3 at 11:01
Does the container actually start? Are you running your script with
sudo
or something else that has the appropriate system-level permission to launch a container? One of your first debugging steps here should be to remote the docker run -d
option and make sure it's actually coming up successfully.– David Maze
Jan 3 at 11:01
I use the ubuntu18.04 installed docker,When test.py is executed, the container has been successfully created.I took a picture of it up here.When I run the command:docker run -d -p 5000:5000 classifier:iris,I use docker container ls,You see that the container is not started, but when I delete the image, it prompts me that the image is being used by the container
– guiniao
Jan 3 at 11:56
I use the ubuntu18.04 installed docker,When test.py is executed, the container has been successfully created.I took a picture of it up here.When I run the command:docker run -d -p 5000:5000 classifier:iris,I use docker container ls,You see that the container is not started, but when I delete the image, it prompts me that the image is being used by the container
– guiniao
Jan 3 at 11:56
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54020470%2fhow-to-combine-docker-and-sklearn%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54020470%2fhow-to-combine-docker-and-sklearn%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
What do you mean by turning it into a docker container? You can always get a container with Python, add sklearn, add the pickled file, and that's a model available in a container.
– Matthieu Brucher
Jan 3 at 10:34
use
docker run -d -p 5000:5000 classifier:iris
in your command prompt or poweshell and then run the commanddocker ps
and show the results– Hansika Madushan Weerasena
Jan 3 at 10:52
1
Does the container actually start? Are you running your script with
sudo
or something else that has the appropriate system-level permission to launch a container? One of your first debugging steps here should be to remote thedocker run -d
option and make sure it's actually coming up successfully.– David Maze
Jan 3 at 11:01
I use the ubuntu18.04 installed docker,When test.py is executed, the container has been successfully created.I took a picture of it up here.When I run the command:docker run -d -p 5000:5000 classifier:iris,I use docker container ls,You see that the container is not started, but when I delete the image, it prompts me that the image is being used by the container
– guiniao
Jan 3 at 11:56