mirror of
https://github.com/hanzo-ml/kserve.git
synced 2026-10-30 20:53:49 +00:00
* Fix python linter Signed-off-by: Sivanantham Chinnaiyan <[email protected]> * Format e2e tests Signed-off-by: Sivanantham Chinnaiyan <[email protected]> * Format hack, docs Signed-off-by: Sivanantham Chinnaiyan <[email protected]> * Add py-fmt target Signed-off-by: Sivanantham Chinnaiyan <[email protected]> * Update python lint workflow Signed-off-by: Sivanantham Chinnaiyan <[email protected]> * Rebase master Signed-off-by: Sivanantham Chinnaiyan <[email protected]> --------- Signed-off-by: Sivanantham Chinnaiyan <[email protected]>
34 lines
962 B
Python
34 lines
962 B
Python
import warnings
|
|
|
|
from sklearn.datasets import fetch_openml
|
|
from sklearn.exceptions import ConvergenceWarning
|
|
from sklearn.neural_network import MLPClassifier
|
|
import joblib
|
|
|
|
# Load data from https://www.openml.org/d/554
|
|
X, y = fetch_openml("mnist_784", version=1, return_X_y=True)
|
|
X = X / 255.0
|
|
X_train, X_test = X[:60000], X[60000:]
|
|
y_train, y_test = y[:60000], y[60000:]
|
|
|
|
mlp = MLPClassifier(
|
|
hidden_layer_sizes=(500, 500, 500),
|
|
max_iter=10,
|
|
alpha=1e-4,
|
|
solver="sgd",
|
|
verbose=10,
|
|
random_state=1,
|
|
learning_rate_init=0.1,
|
|
)
|
|
|
|
# this example won't converge because of CI's time constraints, so we catch the
|
|
# warning and are ignore it here
|
|
with warnings.catch_warnings():
|
|
warnings.filterwarnings("ignore", category=ConvergenceWarning, module="sklearn")
|
|
mlp.fit(X_train, y_train)
|
|
|
|
print("Training set score: %f" % mlp.score(X_train, y_train))
|
|
print("Test set score: %f" % mlp.score(X_test, y_test))
|
|
|
|
joblib.dump(mlp, "model.pkl")
|