| from flask import Flask, request, jsonify |
| from sklearn.tree import DecisionTreeClassifier |
| import numpy as np |
|
|
| app = Flask(__name__) |
|
|
| |
| |
| example_data = [ |
| [0, 0, 1, 1], |
| [1, 1, 0, 0], |
| [1, 0, 1, 0], |
| [0, 1, 0, 1] |
| ] |
|
|
| |
| example_labels = [1, 0, 1, 0] |
|
|
| |
| model = DecisionTreeClassifier() |
| model.fit(example_data, example_labels) |
|
|
| @app.route('/analyze', methods=['POST']) |
| def analyze(): |
| data = request.json |
| response = [data['phishing'], data['ransomware'], data['ddos'], data['malware']] |
| prediction = model.predict([response]) |
| return jsonify({'prediction': int(prediction[0])}) |
|
|
| if __name__ == '__main__': |
| app.run(debug=True) |