-
Notifications
You must be signed in to change notification settings - Fork 0
/
classifyUser.py
executable file
·38 lines (30 loc) · 1 KB
/
classifyUser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from flask import Flask, request
import sklearn
from sklearn.externals import joblib
import numpy as np
app = Flask(__name__)
@app.route('/classifyuser', methods=['POST'])
def classifyUser():
inputData = request.get_json()
friendToFollowerRatio = float(inputData['friendToFollowerRatio'])
urlRatio = float(inputData['urlRatio'])
source = str(inputData['source'])
entropy = inputData['entropy']
reciprocityRatio = float(inputData['reciprocityRatio'])
#Load model
f = open('model.pkl', 'rb')
model = joblib.load(f)
f.close()
#Load encoder
fp = open('encoder.pkl', 'rb')
encoder = joblib.load(fp)
fp.close()
cleanedSource = source.replace("\\", "")
tweet_source = encoder.transform([cleanedSource])
#Row
row_arti = np.array([entropy, friendToFollowerRatio, reciprocityRatio, tweet_source, urlRatio]).reshape(1,5)
#Predict
class_prediced = model.predict(row_arti)[0]
return str(class_prediced)
if __name__=='__main__':
app.run()