From a8f074a76c4b82611d627b88fe028b2e07bb70b5 Mon Sep 17 00:00:00 2001 From: palakkhandelwal123 Date: Mon, 13 Oct 2025 15:11:10 +0530 Subject: [PATCH 1/2] Added FastAPI ML prediction API (supports multiple models) --- models/linear_regressuin.py | 37 ++++++++++++++----------------------- pages/Linear_Regression.md | 24 ++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 23 deletions(-) create mode 100644 pages/Linear_Regression.md diff --git a/models/linear_regressuin.py b/models/linear_regressuin.py index fe3b53a..8ebb33a 100644 --- a/models/linear_regressuin.py +++ b/models/linear_regressuin.py @@ -1,23 +1,14 @@ -# 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 +# models/linear_regression_model.py +from sklearn.linear_model import LinearRegression +import numpy as np + +# Train a simple model for demonstration +model = LinearRegression() +X = np.array([[1], [2], [3], [4], [5]]) +y = np.array([2, 4, 6, 8, 10]) +model.fit(X, y) + +def predict(features): + arr = np.array(features).reshape(1, -1) + prediction = model.predict(arr) + return prediction.tolist() diff --git a/pages/Linear_Regression.md b/pages/Linear_Regression.md new file mode 100644 index 0000000..d87083d --- /dev/null +++ b/pages/Linear_Regression.md @@ -0,0 +1,24 @@ +# Linear Regression Model + +## 🏃‍♂️ How to Run +1. Open the simulator and select **Linear Regression** from the model list. +2. Upload your dataset or use the default sample dataset. +3. Adjust parameters if available, then click **Run Simulation**. + +## ⚙️ Parameters +| Parameter | Description | Default | +|------------|-------------|----------| +| `fit_intercept` | Whether to calculate the intercept term | True | +| `normalize` | Normalize input features before training | False | +| `test_size` | Proportion of data for testing | 0.2 | + +## 📈 Output Plots +- **Scatter Plot:** Shows actual vs. predicted values. +- **Regression Line:** Displays the best-fit line learned by the model. +- **Error Distribution:** Optional plot showing residuals. + +![Linear Regression Output](../assets/linear_regression_output.png) + +## 🧩 Notes +- Works well for linearly related data. +- Avoid using with categorical or highly nonlinear datasets. From 9f17d2c805d05efe82cc64e19dbf66afc7f77313 Mon Sep 17 00:00:00 2001 From: palakkhandelwal123 Date: Mon, 13 Oct 2025 15:15:11 +0530 Subject: [PATCH 2/2] Added helper function to generate classification datasets with adjustable parameters --- utils/data_helpers.py | 55 ++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/utils/data_helpers.py b/utils/data_helpers.py index 80c10f4..5a11a80 100644 --- a/utils/data_helpers.py +++ b/utils/data_helpers.py @@ -1,30 +1,47 @@ # utils/data_helpers.py - -from sklearn.datasets import make_regression +from sklearn.datasets import make_classification import pandas as pd -def generate_sample_regression(n_samples=100, n_features=1, noise=0.0, random_state=None): +def generate_classification_dataset( + n_samples: int = 100, + n_features: int = 10, + n_informative: int = 5, + n_classes: int = 2, + random_state: int = 42 +): """ - Generate a sample regression dataset. + Generate a synthetic classification dataset. - Parameters: - n_samples (int): Number of data points. - n_features (int): Number of features. - noise (float): Standard deviation of Gaussian noise added to the output. - random_state (int or None): Random seed for reproducibility. + Parameters + ---------- + n_samples : int, optional + Number of samples to generate (default=100). + n_features : int, optional + Total number of features (default=10). + n_informative : int, optional + Number of informative features (default=5). + n_classes : int, optional + Number of target classes (default=2). + random_state : int, optional + Random seed for reproducibility (default=42). - Returns: - X (pd.DataFrame): Feature dataframe of shape (n_samples, n_features) - y (pd.Series): Target variable of shape (n_samples,) + Returns + ------- + data : pandas.DataFrame + A DataFrame containing the generated features and target column ('target'). """ - X, y = make_regression( + + X, y = make_classification( n_samples=n_samples, n_features=n_features, - noise=noise, + n_informative=n_informative, + n_redundant=0, + n_classes=n_classes, random_state=random_state ) - # Convert to pandas for convenience - X_df = pd.DataFrame(X, columns=[f'feature_{i+1}' for i in range(n_features)]) - y_series = pd.Series(y, name='target') - - return X_df, y_series + + feature_names = [f"feature_{i}" for i in range(n_features)] + data = pd.DataFrame(X, columns=feature_names) + data["target"] = y + + return data