-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(project): structure refactoring
- Loading branch information
matthieu
committed
Aug 8, 2019
1 parent
b3791aa
commit b2bc8f1
Showing
20 changed files
with
140 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ Alchina is a Machine Learning framework. | |
|
||
**Clusters** | ||
|
||
- K-Means clustering | ||
- K-Means | ||
|
||
**Optimizers** | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
"""Classifiers.""" | ||
|
||
from .linear import LinearClassifier, RidgeClassifier | ||
from .knn import KNNClassifier | ||
|
||
__all__ = ["LinearClassifier", "RidgeClassifier", "KNNClassifier"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
"""Clusters.""" | ||
|
||
from .kmeans import KMeans | ||
|
||
__all__ = ["KMeans"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
"""Optimizers.""" | ||
|
||
from .gradient_descent import GradientDescent, SGD, MBGD | ||
|
||
__all__ = ["GradientDescent", "SGD", "MBGD"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
"""Preprocessors.""" | ||
|
||
from .data import Normalization, Standardization | ||
from .pca import PCA | ||
|
||
__all__ = ["Normalization", "Standardization", "PCA"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"""Data Preprocessors.""" | ||
|
||
import numpy as np | ||
|
||
from typing import Optional | ||
|
||
|
||
class Normalization(object): | ||
"""Rescale the data via a normalization. | ||
Produce: | ||
- Bring all values into the range [0, 1] | ||
""" | ||
|
||
def __call__(self, X, axis: int = 0): | ||
min_x = np.amin(X, axis=axis) | ||
max_x = np.amax(X, axis=axis) | ||
return (X - min_x) / (max_x - min_x) | ||
|
||
|
||
class Standardization(object): | ||
"""Rescale the data via a standardization | ||
Produce: | ||
- mean(Xstandardized) = 0 | ||
- std(Xstandardized) = 1 | ||
""" | ||
|
||
def __init__(self, mu: Optional[int] = None, sigma: Optional[int] = None): | ||
self.mu = mu | ||
self.sigma = sigma | ||
|
||
def __call__(self, X, axis: int = 0): | ||
if self.mu is None or self.sigma is None: | ||
self.mu = np.mean(X, axis=axis) | ||
self.sigma = np.std(X, axis=axis) | ||
|
||
if not np.any(self.sigma): | ||
self.sigma = np.ones_like(self.sigma) | ||
|
||
return np.divide(X - self.mu, self.sigma) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
"""Regressors.""" | ||
|
||
from .linear import LinearRegressor, RidgeRegressor | ||
|
||
__all__ = ["LinearRegressor", "RidgeRegressor"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
"""Clusters tests.""" | ||
"""K-Means tests.""" | ||
|
||
import numpy as np | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
tests/test_optimizers.py → tests/optimizers/test_gradient_descent.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
"""Optimizers tests.""" | ||
"""Gradient Descent Optimizers tests.""" | ||
|
||
import pytest | ||
import numpy as np | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"""Data Preprocessors tests.""" | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
from alchina.preprocessors import Normalization, Standardization | ||
|
||
|
||
# --- Normalization --- | ||
|
||
|
||
def test_normalization(): | ||
"""Test of `Normalization` class.""" | ||
normalize = Normalization() | ||
|
||
X = np.array([1, 10, 100, 5, 0.01]) | ||
X_norm = normalize(X) | ||
|
||
assert np.all((X_norm >= 0) & (X_norm <= 1)) | ||
|
||
|
||
# --- Standardization --- | ||
|
||
|
||
def test_standardization(): | ||
"""Test of `Standardization` class.""" | ||
standardize = Standardization() | ||
|
||
X = np.array([1, 10, 100, 5, 0.01]) | ||
X_stand = standardize(X) | ||
|
||
assert np.mean(X_stand) == pytest.approx(0) | ||
assert np.std(X_stand) == pytest.approx(1) |
31 changes: 2 additions & 29 deletions
31
tests/test_preprocessors.py → tests/preprocessors/test_pca.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/test_regressors.py → tests/regressors/test_linear_regressors.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
"""Regressors tests.""" | ||
"""Linear Regressors tests.""" | ||
|
||
import numpy as np | ||
import pytest | ||
|