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
37 changes: 14 additions & 23 deletions models/linear_regressuin.py
Original file line number Diff line number Diff line change
@@ -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()
24 changes: 24 additions & 0 deletions pages/Linear_Regression.md
Original file line number Diff line number Diff line change
@@ -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.
55 changes: 36 additions & 19 deletions utils/data_helpers.py
Original file line number Diff line number Diff line change
@@ -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