Skip to content

Instantly share code, notes, and snippets.

@thuwarakeshm
Last active February 19, 2023 09:59
Show Gist options
  • Save thuwarakeshm/c47d05526c545d329700e649f9ff2384 to your computer and use it in GitHub Desktop.
Save thuwarakeshm/c47d05526c545d329700e649f9ff2384 to your computer and use it in GitHub Desktop.
deploy ml
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
df = pd.read_csv('titanic.csv')
x = df[df.columns.difference(['Survived'])
y = df['Survived']
classifier = RandomForestClassifier()
classifier.fit(x, y)
from sklearn.externals import joblib
joblib.dump(classifier, 'classifier.pkl')
from flask import Flask
app = Flask(__name__)
@app.route('/predict', methods=['POST'])
def predict():
json_ = request.json
query_df = pd.DataFrame(json_)
query = pd.get_dummies(query_df)
classifier = joblib.load('classifier.pkl')
prediction = classifier.predict(query)
return jsonify({'prediction': list(prediction)})
if __name__ == '__main__':
app.run(port=8080)
@inokentiyTTT
Copy link

inokentiyTTT commented Feb 19, 2023

Hi, thunk for posting this example, I think here is some err brackets not closing
https://gist.github.com/thuwarakeshm/c47d05526c545d329700e649f9ff2384/1d18360f32e4e28a14a82c811ad7e33edb0c7cd0#file-load-py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment