I have already finished my function, but when I run the webserver I get the following error:
TypeError : index() missing 1 required positional argument:'input'
This is my code:
from sklearn import tree
from flask import Flask
app = Flask(__name__)
@app.route('/', methods=['GET','POST'])
def index(input):
input = [[1,1,2,3,3,1,1,2]]
data = pd.read_csv('datawadek.csv')
y = data.KELAS
x = data.drop('KELAS', axis = 1)
cart = tree.DecisionTreeClassifier()
cart = cart.fit(x,y)
return cart.predict(input)
if __name__ == '__main__':
app.run(debug=True)
I am very new to python programming. Please help me with any suggestions or solutions.
Have a nice day
I assume that you want to pass input as a parameter in flask. You cannot define the input as parameters to your flask's endpoint function. Instead, you should read the parameters inside the said function with
request.args.getlike this:From python docs:
EDIT:
In the comments we had a similar example with path parameter:
the final result will be identical to my initial answer above, but it less practical from design standpoint. You would be using a post method to pass an array of data and in this case, the data should come inside a request.
Another reason to not do it is that you should also always avoid passing an array as a path parameter unless