Created
December 26, 2022 17:20
-
-
Save y1450/e6ea874be686ea5a773fd24078843c7e to your computer and use it in GitHub Desktop.
sklearn-pickle-model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM python:3.9.1 | |
COPY logistic_regression.py logistic_regression.py | |
COPY load_model.py load_model.py | |
COPY runner.sh runner.sh | |
ENTRYPOINT [ "bash", "runner.sh" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pickle | |
with open("log_reg_iris.pkl","rb") as f: | |
model = pickle.load(f) | |
print(model) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#https://scikit-learn.org/dev/modules/generated/sklearn.linear_model.LogisticRegression.html | |
from sklearn.datasets import load_iris | |
from sklearn.linear_model import LogisticRegression | |
import pickle | |
X, y = load_iris(return_X_y=True) | |
clf = LogisticRegression(random_state=0).fit(X, y) | |
clf.predict(X[:2, :]) | |
clf.predict_proba(X[:2, :]) | |
clf.score(X, y) | |
with open("log_reg_iris.pkl","wb") as f: | |
pickle.dump(clf,f) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!bin/bash | |
python3 -m venv venv_sklearn_1.0 | |
source venv_sklearn_1.0/bin/activate | |
pip install scikit-learn=="1.0" | |
python logistic_regression.py | |
python3 -m venv venv_sklearn_1.1 | |
source venv_sklearn_1.1/bin/activate | |
pip install scikit-learn=="1.1" | |
python load_model.py |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment