Pass Python code to html

0

I have made a time predictor with python and sklearn. I would like to capture the data ("humidity" and "wind") using an html form (use of input), then check them in python and finally return the response in the html file (the data on whether it is raining or not). I had thought about doing it by writing a text document and having it read by python, but I do not know how that could be done. Next, the python code, how could you implement it in html?

from sklearn import tree

clf = tree.DecisionTreeClassifier()

# Weather informartion. [ humidity , wind]

def weatherprediction (humidity,wind)

X = [[88 , 125 ] ,[23,15] ,[79,200] , [44,45],[68,111],[35,30] ,[22,10],[38,10],[39,150] , [97,20]]

Y = ['Rain','Dont rain','Rain','Rain','Rain','Dont rain','Dont rain','Dont rain','Dont rain','Rain']

clf = clf.fit(X,Y)   #The program learn how the informantion is related

prediction = clf.predict([[humidity,wind]])

print(prediction)
    
asked by David Barrero 07.08.2018 в 19:21
source

1 answer

0

I recommend using the Django framework (1), which allows you to connect Python with HTML. DJANGO works by default with mysqli, but you can connect it with the database of your choice. Check the attached manual in the references

You could consider the following logical model for the database:

These tables would be represented in the "models" folder of DJANGO. The values of the variable "x" and the variable "y" would be obtained from the database, then you do the training with "fit", the prediction with "predict" and the resulting data you return using the DJANGO template system .

References:

(1) DJANGO 2.0 Manual. link

    
answered by 07.08.2018 / 20:31
source