Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions api/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from models.linear_regression import LinearRegressionModel
from models.logistic_regression import LogisticRegressionModel

app = FastAPI(title="ML Simulator API", version="1.0")

# Example input format
class ModelInput(BaseModel):
model_name: str
features: list[float]

@app.post("/predict")
def predict(data: ModelInput):
model_name = data.model_name.lower()
features = data.features

if model_name == "linear_regression":
model = LinearRegressionModel()
elif model_name == "logistic_regression":
model = LogisticRegressionModel()
else:
raise HTTPException(status_code=400, detail="Model not found")

try:
prediction = model.predict(features)
return {"model": model_name, "prediction": prediction}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
11 changes: 11 additions & 0 deletions models/linear_regression.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import numpy as np

class LinearRegressionModel:
def __init__(self):
# Placeholder coefficients
self.coefficients = [1.5, -0.7, 0.3]
self.bias = 2.0

def predict(self, features):
x = np.array(features)
return float(np.dot(self.coefficients, x) + self.bias)
23 changes: 0 additions & 23 deletions models/linear_regressuin.py

This file was deleted.