diff --git a/api/main.py b/api/main.py new file mode 100644 index 0000000..39faceb --- /dev/null +++ b/api/main.py @@ -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)) diff --git a/models/linear_regression.py b/models/linear_regression.py new file mode 100644 index 0000000..77fcce7 --- /dev/null +++ b/models/linear_regression.py @@ -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) diff --git a/models/linear_regressuin.py b/models/linear_regressuin.py deleted file mode 100644 index fe3b53a..0000000 --- a/models/linear_regressuin.py +++ /dev/null @@ -1,23 +0,0 @@ -# Contributing Guide - -We ❤️ contributions! This project is part of **Hacktoberfest**. - -## Steps to Contribute -1. Fork the repo -2. Create a new branch (`git checkout -b feature-model`) -3. Add your model/page under `/pages` -4. Use helper functions from `/utils` -5. Commit and push (`git push origin feature-model`) -6. Open a Pull Request (PR) - -## What You Can Work On -- Add a new ML model (e.g., Decision Tree, KNN, SVM, etc.) -- Improve plotting helpers -- Add more datasets to `data_helpers` -- Enhance UI/UX in Streamlit - -## Labels -- `good first issue` → beginner-friendly -- `feature` → add a new model -- `bug` → fix something broken -- `documentation` → improve docs