# You'll use the SigOpt Training Runs API to communicate with SigOpt
# while your model is running on the cluster.
# These packages will need to be installed in order to run your model.
# To do this, define a requirements.txt file, and provide instructions
from sklearn import datasets
from sklearn.linear_model import SGDClassifier
from sklearn.model_selection import cross_val_score
# https://en.wikipedia.org/wiki/Iris_flower_data_set
iris = datasets.load_iris()
return (iris.data, iris.target)
def evaluate_model(X, y):
sigopt.params.setdefaults(
classifier = SGDClassifier(
penalty=sigopt.params.penalty,
alpha=10 ** sigopt.params.log_alpha,
l1_ratio=sigopt.params.l1_ratio,
max_iter=sigopt.params.max_iter,
cv_accuracies = cross_val_score(classifier, X, y, cv=5)
return (numpy.mean(cv_accuracies), numpy.std(cv_accuracies))
# Each execution of model.py should represent one evaluation of your model.
# When this file is run, it loads data, evaluates the model using assignments
if __name__ == "__main__":
(mean, std) = evaluate_model(X=X, y=y)
print("Accuracy: {} +/- {}".format(mean, std))
sigopt.log_metric("accuracy", mean, std)