Open Igigoto opened 4 months ago
from flask import Flask, request, jsonify import numpy as np from perceptron import Perceptron
app = Flask(name)
model = Perceptron() model.fit(np.array([[1,1], [2,2], [3,3], [4,4]]), np.array([0, 0, 1, 1]))
@app.route('/predict', methods=['POST']) def predict(): data = request.get_json(force=True) prediction = model.predict(np.array(data['features'])) return jsonify({'prediction': prediction.tolist()})
if name == 'main': app.run(host='0.0.0.0', port=5000)
Flask
perceptron.py
import numpy as np
class Perceptron: def init(self, learning_rate=0.01, n_iters=1000): self.learning_rate = learning_rate self.n_iters = n_iters self.activation_func = self._unit_step_func self.weights = None self.bias = None