Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 4 Normalizing methods for data preprocessing and update Readme.md #95

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ but rather to present the inner workings of them in a transparent and accessible
+ [Genetic Algorithm](#genetic-algorithm)
+ [Association Analysis](#association-analysis)
* [Implementations](#implementations)
+ [Normalizing](#normalizing)
+ [Supervised Learning](#supervised-learning)
+ [Unsupervised Learning](#unsupervised-learning)
+ [Reinforcement Learning](#reinforcement-learning)
Expand Down Expand Up @@ -267,6 +268,11 @@ but rather to present the inner workings of them in a transparent and accessible


## Implementations
### Normalizing
- [MinMaxScaler](mlfromscratch/normalizing/minmaxscaler.py)
- [StandardScaler](mlfromscratch/normalizing/standardscaler.py)
- [StandardScaler With Selective mean and variance](mlfromscratch/normalizing/standardscalerwithmv.py)
- [MaxAbsScaler](mlfromscratch/normalizing/maxabsscaler.py)
### Supervised Learning
- [Adaboost](mlfromscratch/supervised_learning/adaboost.py)
- [Bayesian Regression](mlfromscratch/supervised_learning/bayesian_regression.py)
Expand Down
4 changes: 4 additions & 0 deletions mlfromscratch/normalizing/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .minmaxscaler import MinMaxScaler
from .standardscaler import StandardScaler
from .standardscalerwithmv import StandardScalerAdv
from .maxabsscaler import MaxAbsScaler
11 changes: 11 additions & 0 deletions mlfromscratch/normalizing/maxabsscaler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from __future__ import print_function, division
import numpy as np

def MaxAbsScaler(x):
"""
Parameters :
x : Dataset

"""
normalized = x/np.max(abs(x))
return normalized
13 changes: 13 additions & 0 deletions mlfromscratch/normalizing/minmaxscaler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from __future__ import print_function, division
import numpy as np

def MinMaxScaler(x,minmax):
"""
Parameters :
x : Dataset
minmax : the minimum and maximum range of your features

"""
normalized = (x-np.min(x))/(np.max(x)-np.min(x))
scale = (normalized * (np.max(minmax)-np.min(minmax))) + np.min(minmax)
return scale
16 changes: 16 additions & 0 deletions mlfromscratch/normalizing/standardscaler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from __future__ import print_function, division
import numpy as np

def StandardScaler(x,standard=True):
"""
Parameters :
x : Dataset
standard : True or False (True = setting the mean of 0 and var of 1, False = computing mean and var of data)

"""
if standard == True:
normalized = (x-0)/np.sqrt(1)

else:
normalized = (x-np.mean(x))/np.std(x)
return normalized
12 changes: 12 additions & 0 deletions mlfromscratch/normalizing/standardscalerwithmv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from __future__ import print_function, division
import numpy as np

def StandardScalerAdv(x,mean,var):
"""
Parameters :
x : Dataset
mean : your favorite mean for scaling features
var : your favorite variance for scaling features

"""
normalized = (x-mean)/np.sqrt(var)