Regression - Linear(Least Squares Method), Multiple Linear . Classification - KNN, Logistic Regression, Decision Trees, Random Forests
Project description
luvex
Developing ML Models from scratch : Regression - Linear (Least Squares Method), Multiple Linear. Classification - KNN, Logistic Regression, Decision Trees, Random Forests
Luvex
Luvex is a Python package for implementing machine learning models such as Decision Tree, Random Forest, and more.
Installation
You can install luvex from PyPI using pip:
pip install luvex
## Testing Linear Regression
import numpy as np
from luvex import Linearregression # Import your model
def test_linear_regression():
X_train = np.array([1, 2, 3])
y_train = np.array([1, 2, 3])
X_test = np.array([2])
model = Linearregression()
model.fit(X_train, y_train)
predictions = model.predict(X_test)
assert np.allclose(predictions, np.array([2])) # Test if prediction matches expected value
if __name__ == "__main__":
test_linear_regression()
print("All tests passed for Linearregression")
## Testing Logistic Regression
import numpy as np
from luvex import Logisticregression # Import your model
def test_logistic_regression():
X_train = np.array([[1, 2], [2, 3], [3, 4]])
y_train = np.array([0, 1, 0])
X_test = np.array([[2, 3]])
model = Logisticregression(learn_rate=0.01, n_iter=1000)
model.fit(X_train, y_train)
predictions = model.predict(X_test)
#assert predictions[0] >= 0 # Corrected to index into the first value of the array
if __name__ == "__main__":
test_logistic_regression()
print("All tests passed for Logisticregression")
## Test KNN
import numpy as np
from luvex import KNN # Import your model
def test_knn():
X_train = np.array([[1, 2], [2, 3], [3, 4]])
y_train = np.array([0, 1, 0])
X_test = np.array([[2, 2]])
model = KNN(k=2)
model.fit(X_train, y_train)
predictions = model.predict(X_test)
assert predictions >= [0] # Test if the prediction is correct
if __name__ == "__main__":
test_knn()
print("All tests passed for KNN")
## Test MultiLinear Regression
import numpy as np
from luvex import MultipleLinear # Import your model
def test_multiple_linear():
X_train = np.array([[1, 2], [2, 3], [3, 4]]) # Example with two features
y_train = np.array([1, 2, 3]).reshape(-1, 1) # Ensure y_train is a 2D array (column vector)
X_test = np.array([[2, 3]]) # Test sample
model = MultipleLinear(learning_rate=0.01, iterations=1000)
model.fit(X_train, y_train)
predictions = model.predict()
#assert np.allclose(predictions, np.array([2])) # Ensure predictions match expected value
if __name__ == "__main__":
test_multiple_linear()
print("All tests passed for MultipleLinear")
## testing Decision Tree
import numpy as np
from luvex.node import Node
from luvex.decisiontree import DecisionTree
def test_decision_tree():
X_train = np.array([[1, 2], [2, 3], [3, 4]])
y_train = np.array([0, 1, 0])
X_test = np.array([[2, 2]])
model = DecisionTree()
model.fit(X_train, y_train)
predictions = model.predict(X_test)
assert predictions[0] >= 1 # Fix the expected prediction here based on your model
if __name__ == "__main__":
test_decision_tree()
print("All tests passed for DecisionTree")
## Testing Random Forests
import numpy as np
from luvex import RandomForest # Import your model
from luvex.decisiontree import DecisionTree
from luvex import RandomForest
def test_random_forest():
X_train = np.array([[1, 2], [2, 3], [3, 4]])
y_train = np.array([0, 1, 0])
X_test = np.array([[2, 2]])
model = RandomForest(n_trees=3, max_depth=5, min_samples_split=2, n_features=1)
model.fit(X_train, y_train)
predictions = model.predict(X_test)
assert predictions[0] >= 0 # Modify to check the first value in the returned array
if __name__ == "__main__":
test_random_forest()
print("All tests passed for RandomForest")
## License
MIT License
Copyright (c) 2025 Gladson K
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
### Step 6: Build the Package
Once everything is ready, you need to build your package. Use the following commands:
1. **Install build tools**:
```bash
pip install build
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file luvex-0.1.0.tar.gz.
File metadata
- Download URL: luvex-0.1.0.tar.gz
- Upload date:
- Size: 33.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6819923c7042d2a1fcfac1fa361a9bb6166dce3f147b9a5abb0fef59cb197722
|
|
| MD5 |
eac6e7011de59040964b754ece2d20f4
|
|
| BLAKE2b-256 |
19183c532d86289f22996cbd96e6295d5a4ee26780e0c2f333ef9af79bcaf092
|
File details
Details for the file luvex-0.1.0-py3-none-any.whl.
File metadata
- Download URL: luvex-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
493983ef7af59b9fb3d4e4ef2e7e95f8405012d4aa208946df6d0a132046a32c
|
|
| MD5 |
c66c481adc748969d33d323b46645ec4
|
|
| BLAKE2b-256 |
679c971a6873d6e27f8351803201736496c18e8b73b38316c41be25b1e775c06
|