├── .DS_Store ├── README.md ├── app.py ├── clf.pkl ├── data.csv ├── model.py └── templates ├── .DS_Store └── website.html /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerchristko/Machine-Learning-Web-App/014ab4a9aed9075c0807363584331f87247e3498/.DS_Store -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Machine-Learning-API 2 | Made for a medium article I wrote. Link [here](https://towardsdatascience.com/building-a-machine-learning-web-application-using-flask-29fa9ea11dac). -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, request, render_template 2 | import pandas as pd 3 | import joblib 4 | 5 | 6 | # Declare a Flask app 7 | app = Flask(__name__) 8 | 9 | @app.route('/', methods=['GET', 'POST']) 10 | def main(): 11 | 12 | # If a form is submitted 13 | if request.method == "POST": 14 | 15 | # Unpickle classifier 16 | clf = joblib.load("clf.pkl") 17 | 18 | # Get values through input bars 19 | height = request.form.get("height") 20 | weight = request.form.get("weight") 21 | 22 | # Put inputs to dataframe 23 | X = pd.DataFrame([[height, weight]], columns = ["Height", "Weight"]) 24 | 25 | # Get prediction 26 | prediction = clf.predict(X)[0] 27 | 28 | else: 29 | prediction = "" 30 | 31 | return render_template("website.html", output = prediction) 32 | 33 | # Running the app 34 | if __name__ == '__main__': 35 | app.run(debug = True) -------------------------------------------------------------------------------- /clf.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerchristko/Machine-Learning-Web-App/014ab4a9aed9075c0807363584331f87247e3498/clf.pkl -------------------------------------------------------------------------------- /data.csv: -------------------------------------------------------------------------------- 1 | Height,Weight,Species 2 | 88.9,48.3,Dog 3 | 90.2,47.4,Dog 4 | 82.7,44.8,Dog 5 | 81.4,48.2,Dog 6 | 83.5,39.9,Dog 7 | 76.4,35.4,Cat 8 | 82.3,40.4,Cat 9 | 81.1,39.9,Cat 10 | 79.9,43.2,Cat 11 | 82.4,45.7,Cat -------------------------------------------------------------------------------- /model.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | from sklearn.naive_bayes import GaussianNB 3 | 4 | 5 | df = pd.read_csv("data.csv") 6 | 7 | X = df[["Height", "Weight"]] 8 | y = df["Species"] 9 | 10 | clf = GaussianNB() 11 | clf.fit(X, y) 12 | 13 | import joblib 14 | 15 | joblib.dump(clf, "clf.pkl") 16 | -------------------------------------------------------------------------------- /templates/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerchristko/Machine-Learning-Web-App/014ab4a9aed9075c0807363584331f87247e3498/templates/.DS_Store -------------------------------------------------------------------------------- /templates/website.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |{{ output }}
17 | 18 | --------------------------------------------------------------------------------