Skip to content
Snippets Groups Projects
Commit a889cae4 authored by Fabian Pedregosa's avatar Fabian Pedregosa
Browse files

Add learn.preprocessing, for data pre processing

From: cdavid <cdavid@cb17146a-f446-4be1-a4f7-bd7c5bb65646>

git-svn-id: https://scikit-learn.svn.sourceforge.net/svnroot/scikit-learn/trunk@11 22fbfee3-77ab-4535-9bad-27d1bd3bc7d8
parent 552535a1
No related merge requests found
#! /usr/bin/env python
# Last Change: Mon Jul 09 08:00 PM 2007 J
# Various utilities for examples
import numpy as N
"""Different tools for pre processing, like whitening or scaling data."""
def scale(data, mode = 'sym'):
"""Linearly scale data in place such as each col is in the range [0..1].
Returns the translation factor t and scaling factor s. You can retrieve
the original values with data = s * scaled + t."""
n = N.min(data, 0)
m = N.max(data, 0)
if mode == 'sym':
t = n + 0.5 * (m - n)
s = 0.5 * (m - n)
elif mode == 'right':
t = n
s = m - n
else:
raise ValueError("Mode %s not recognized" % mode)
data -= t
data /= s
return t, s
def whiten():
"""Whiten data."""
raise NotImplementedError("whitening not implemented yet")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment