<jupyter_start><jupyter_text>Building a simple model<jupyter_code># import some data to play with
iris = datasets.load_iris()
X = iris.data
y = iris.target

print(iris.DESCR)
X_train, X_test, y_train, y_test = train_test_split(X, y)
rfc = RandomForestClassifier(n_estimators=100, n_jobs=2)
rfc.fit(X_train, y_train)
print("Accuracy = %0.2f" % accuracy_score (y_test, rfc.predict(X_test)))
print(classification_report(y_test, rfc.predict(X_test)))<jupyter_output>Accuracy = 0.97
              precision    recall  f1-score   support

           0       1.00      1.00      1.00        17
           1       1.00      0.92      0.96        13
           2       0.89      1.00      0.94         8

   micro avg       0.97      0.97      0.97        38
   macro avg       0.96      0.97      0.97        38
weighted avg       0.98      0.97      0.97        38<jupyter_text>Model serialization / marshalling<jupyter_code>pickle.dump(rfc, open("iris_rfc.pkl", "wb"))
my_random_forest = pickle.load(open("iris_rfc.pkl", "rb"))
my_random_forest
print(classification_report(y_test, my_random_forest.predict(X_test)))<jupyter_output>precision    recall  f1-score   support

           0       1.00      1.00      1.00        17
           1       1.00      0.92      0.96        13
           2       0.89      1.00      0.94         8

   micro avg       0.97      0.97      0.97        38
   macro avg       0.96      0.97      0.97        38
weighted avg       0.98      0.97      0.97        38<jupyter_text>Next we will start a flask service.   That's in the file 'flask_demo.py'Once it's started, we can use this bit of code to call it.<jupyter_code>url = "http://localhost:9000/api"
data = json.dumps({'sl':5.84,'sw':3.0, 'pl':3.75,'pw':1.1}) 
print(data)
r = requests.post(url, data)

print(r.json())<jupyter_output>{"sl": 5.84, "sw": 3.0, "pl": 3.75, "pw": 1.1}
{'results': {'y_hat': 1}}
{'fraction_non_alphanumeric': 0.12076271186440678, 'fraction_numerical': 0.09110169491525423, 'mean_word_length': 1.9748031496062992, 'pattern_counts': {'":': 4, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '568261', 'license': 'MIT', 'n_tokens_mistral': 794, 'n_tokens_neox': 714, 'n_words': 161, 'path': 'productionize_model_w_flask.ipynb', 'repo_name': 'sai-sondarkar/HR-Recommender', 'size': '1888'}