Skip to content

Commit 68a3eaa

Browse files
authored
Add Mojmelo (#33)
* Add Mojmelo * removed trailing whitespace * mojmelo - try to fix ruff format * mojmelo - try to fix recipe errors * mojmelo - try to fix test errors * Update recipe.yaml * mojmelo - fixed indentation error * included custom python test file to recipe * mojmelo - try to import sklearn * mojmelo - try to import sklearn * mojmelo - try to import sklearn
1 parent 2013bac commit 68a3eaa

File tree

6 files changed

+179
-0
lines changed

6 files changed

+179
-0
lines changed

recipes/mojmelo/README.md

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<a id="readme-top"></a>
2+
3+
[![Stargazers][stars-shield]][stars-url]
4+
[![Issues][issues-shield]][issues-url]
5+
[![BSD-3-Clause License][license-shield]][license-url]
6+
![CodeQL](https://github.com/yetalit/Mojmelo/workflows/CodeQL/badge.svg)
7+
8+
<br />
9+
<div align="center">
10+
<a href="https://github.com/yetalit/mojmelo">
11+
<img src="./image.jpeg" alt="Logo" width="256" height="256">
12+
</a>
13+
<h3 align="center">Mojmelo</h3>
14+
<p align="center">
15+
<a href="https://github.com/yetalit/mojmelo/issues/new?labels=bug&template=bug-report---.md">Report Bug</a>
16+
·
17+
<a href="https://github.com/yetalit/mojmelo/issues/new?labels=enhancement&template=feature-request---.md">Request Feature</a>
18+
</p>
19+
</div>
20+
21+
## About The Project
22+
23+
The name `Mojmelo` is derived from the "Mojo Machine Learning" expression. It includes the implementation of Machine Learning algorithms from scratch in pure Mojo.
24+
Here is the list of the algorithms:
25+
* Linear Regression
26+
* Polynomial Regression
27+
* Logistic Regression
28+
* KNN
29+
* KMeans
30+
* DBSCAN
31+
* SVM
32+
1. Primal
33+
2. Dual
34+
* Perceptron (single layer: Binary Classification)
35+
* Naive Bayes
36+
1. GaussianNB
37+
2. MultinomialNB
38+
* Decision Tree (both Regression/Classification)
39+
* Random Forest (both Regression/Classification)
40+
* GBDT (both Regression/Classification)
41+
* PCA
42+
* LDA
43+
* Adaboost
44+
45+
Preprocessing:
46+
* normalize
47+
* MinMaxScaler
48+
* StandardScaler
49+
* KFold
50+
* GridSearchCV
51+
52+
**Mojmelo will not only be limited to above algorithms.**
53+
54+
## Getting Started
55+
56+
The following steps let you know how to get started with Mojmelo.
57+
58+
### Prerequisites
59+
60+
* Mojo compiler
61+
62+
Additionally, you may want to install bellow Python packages for a better usability and to run tests:
63+
1. Numpy
64+
2. Pandas
65+
3. Scikit-learn
66+
4. Matplotlib
67+
68+
## Usage
69+
70+
Just import any model you want this way:
71+
```python
72+
from mojmelo.LinearRegression import LinearRegression
73+
```
74+
You may also want to use the utility codes I've written for this project:
75+
```python
76+
from mojmelo.utils.Matrix import Matrix
77+
from mojmelo.utils.utils import *
78+
```
79+
80+
## Contributing
81+
82+
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.
83+
84+
You can contribute to the project in 3 ways:
85+
1. Apply improvements to the code and Open a Pull Request
86+
2. Report a bug
87+
3. Suggest new features
88+
89+
<!-- ACKNOWLEDGMENTS -->
90+
## Acknowledgments
91+
92+
Took inspiration from Patrick Loeber's <a href='https://github.com/patrickloeber/MLfromscratch/'>MLfromscratch</a> and Erik Linder-Norén's <a href='https://github.com/eriklindernoren/ML-From-Scratch/'>ML-From-Scratch</a>
93+
94+
Mojo usage and distribution is licensed under the [MAX & Mojo Community License](https://www.modular.com/legal/max-mojo-license).
95+
96+
97+
[stars-shield]: https://img.shields.io/github/stars/yetalit/mojmelo?style=social
98+
[stars-url]: https://github.com/yetalit/mojmelo/stargazers
99+
[issues-shield]: https://img.shields.io/github/issues/yetalit/mojmelo
100+
[issues-url]: https://github.com/yetalit/mojmelo/issues
101+
[license-shield]: https://img.shields.io/badge/license-BSD%203--Clause-blue
102+
[license-url]: https://github.com/yetalit/Mojmelo/blob/main/LICENSE

recipes/mojmelo/avatar.jpeg

109 KB
Loading

recipes/mojmelo/image.jpeg

159 KB
Loading

recipes/mojmelo/recipe.yaml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
context:
2+
version: "0.0.1"
3+
4+
package:
5+
name: "mojmelo"
6+
version: ${{ version }}
7+
8+
source:
9+
- git: https://github.com/yetalit/mojmelo.git
10+
rev: c17c802105f65aa4fc2811f60cf8b099bae8f9ca
11+
12+
build:
13+
number: 0
14+
script:
15+
- mojo package mojmelo -o ${{ PREFIX }}/lib/mojo/mojmelo.mojopkg
16+
requirements:
17+
host:
18+
- max
19+
run:
20+
- ${{ pin_compatible('max') }}
21+
22+
tests:
23+
- script:
24+
- if: unix
25+
then:
26+
- mojo run tests/LogisR_test.mojo
27+
requirements:
28+
run:
29+
- scikit-learn
30+
files:
31+
recipe:
32+
- tests/LogisR_test.mojo
33+
- tests/load_breast_cancer.py
34+
35+
about:
36+
homepage: https://github.com/yetalit/Mojmelo
37+
license: BSD-3-Clause
38+
license_file: LICENSE
39+
summary: Machine Learning algorithms in pure Mojo.
40+
repository: https://github.com/yetalit/Mojmelo
41+
42+
extra:
43+
project_name: Mojmelo
44+
maintainers:
45+
- yetalit
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from mojmelo.LogisticRegression import LogisticRegression
2+
from mojmelo.utils.Matrix import Matrix
3+
from mojmelo.utils.preprocessing import train_test_split, GridSearchCV
4+
from mojmelo.utils.utils import accuracy_score
5+
from collections import Dict
6+
from python import Python
7+
8+
def main():
9+
lr_test = Python.import_module("load_breast_cancer")
10+
data = lr_test.get_data() # X, y
11+
X = Matrix.from_numpy(data[0])
12+
y = Matrix.from_numpy(data[1]).T()
13+
params = Dict[String, List[String]]()
14+
params['learning_rate'] = List[String]('0.001', '0.01', '0.1')
15+
params['n_iters'] = List[String]('100', '500', '1000')
16+
params['method'] = List[String]('gradient', 'newton')
17+
params['tol'] = List[String]('0.001', '0.01', '0.1')
18+
params['reg_alpha'] = List[String]('0.001', '0.005', '0.01')
19+
best_params, _ = GridSearchCV[LogisticRegression](X, y, params, accuracy_score, cv=4)
20+
print('tuned parameters: ', best_params.__str__())
21+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=1234)
22+
lr = LogisticRegression(best_params)
23+
lr.fit(X_train, y_train)
24+
y_pred = lr.predict(X_test)
25+
print("LR classification accuracy:", accuracy_score(y_test, y_pred))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from sklearn import datasets
2+
3+
4+
def get_data():
5+
data = datasets.load_breast_cancer()
6+
7+
return [data.data, data.target]

0 commit comments

Comments
 (0)