<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>feature scaling Archives - Creatronix</title>
	<atom:link href="https://creatronix.de/tag/feature-scaling/feed/" rel="self" type="application/rss+xml" />
	<link>https://creatronix.de/tag/feature-scaling/</link>
	<description>My adventures in code &#38; business</description>
	<lastBuildDate>Mon, 06 Jan 2025 09:41:23 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.4</generator>
	<item>
		<title>Feature Scaling</title>
		<link>https://creatronix.de/feature-scaling/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Fri, 05 Oct 2018 08:29:19 +0000</pubDate>
				<category><![CDATA[Data Science & SQL]]></category>
		<category><![CDATA[feature scaling]]></category>
		<category><![CDATA[machine learning]]></category>
		<category><![CDATA[minmaxscaler]]></category>
		<guid isPermaLink="false">http://creatronix.de/?p=1837</guid>

					<description><![CDATA[<p>What is Feature Scaling? Feature Scaling is an important pre-processing step for some machine learning algorithms. Imagine you have three friends of whom you know the individual weight and height. You would like to deduce Christian&#8217;s  t-shirt size from David&#8217;s and Julia&#8217;s by looking at the height and weight. Name Height in m Weight in&#8230;</p>
<p>The post <a href="https://creatronix.de/feature-scaling/">Feature Scaling</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>What is Feature Scaling?</h2>
<p><img fetchpriority="high" decoding="async" class="alignnone size-full wp-image-1969" src="https://creatronix.de/wp-content/uploads/2018/08/feature_scaling.jpg" alt="" width="568" height="335" srcset="https://creatronix.de/wp-content/uploads/2018/08/feature_scaling.jpg 568w, https://creatronix.de/wp-content/uploads/2018/08/feature_scaling-300x177.jpg 300w" sizes="(max-width: 568px) 100vw, 568px" /></p>
<p>Feature Scaling is an important pre-processing step for some machine learning algorithms.</p>
<p>Imagine you have three friends of whom you know the individual weight and height.</p>
<p>You would like to deduce Christian&#8217;s  t-shirt size from David&#8217;s and Julia&#8217;s by looking at the height and weight.</p>
<table class="table-striped">
<thead>
<tr>
<th>Name</th>
<th>Height in m</th>
<th>Weight in kg</th>
<th>T-Shirt size</th>
</tr>
</thead>
<tbody>
<tr>
<td>Julia</td>
<td>1.58</td>
<td>52</td>
<td>Small</td>
</tr>
<tr>
<td>David</td>
<td>1.79</td>
<td>79</td>
<td>Large</td>
</tr>
<tr>
<td>Christian</td>
<td>1.86</td>
<td>64</td>
<td>?</td>
</tr>
</tbody>
</table>
<p>One way You could determine the shirt size is to just add up the weight and the height of each friend. You would get:<span id="more-1837"></span></p>
<table class="table-striped">
<thead>
<tr>
<th>Name</th>
<th>Height + weight</th>
<th>T-Shirt size</th>
</tr>
</thead>
<tbody>
<tr>
<td>Julia</td>
<td>53.58</td>
<td>Small</td>
</tr>
<tr>
<td>David</td>
<td>80.79</td>
<td>Large</td>
</tr>
<tr>
<td>Christian</td>
<td>65.86</td>
<td></td>
</tr>
</tbody>
</table>
<p>Because Christian&#8217;s height + weight number is nearer to Julia&#8217;s number than to David&#8217;s, Christian should wear a small T-Shirt. What?</p>
<h2>Feature Scaling Formula</h2>
<blockquote><p>x&#8217; = (x &#8211; x<sub>min)</sub> / (x<sub>max</sub> &#8211; x<sub>min</sub>)</p></blockquote>
<p>&nbsp;</p>
<table class="table-striped">
<thead>
<tr>
<th>Feature</th>
<th>min</th>
<th>max</th>
</tr>
</thead>
<tbody>
<tr>
<td>Height</td>
<td>1.58</td>
<td>1.86</td>
</tr>
<tr>
<td>Weight</td>
<td>52</td>
<td>79</td>
</tr>
</tbody>
</table>
<table class="table-striped">
<thead>
<tr>
<th>Name</th>
<th>Scaled Height</th>
<th>Scaled Weight</th>
<th>Combined Scaled Height + Weight</th>
<th>T-Shirt size</th>
</tr>
</thead>
<tbody>
<tr>
<td>Julia</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>Small</td>
</tr>
<tr>
<td>David</td>
<td>0.75</td>
<td>1</td>
<td>1.75</td>
<td>Large</td>
</tr>
<tr>
<td>Christian</td>
<td>1</td>
<td>0.44</td>
<td>1.44</td>
<td>?</td>
</tr>
</tbody>
</table>
<p>If we look at the combined scaled properties we see that Christian&#8217;s value now is closer to David&#8217;s so we deduce that Christian shall wear a large shirt as well.</p>
<h2>Implementing feature scaling in python</h2>
<p>As a little coding practice we can implement a feature scaling algorithm in Python:</p>
<pre>def feature_scaling(arr):
    ret_arr = []
    min_val = min(arr)
    max_val = max(arr)
    if min_val == max_val:
        raise ZeroDivisionError()
    for f in arr:
        f = (f - min_val) / float((max_val - min_val))
        ret_arr.append(f)
    return ret_arr</pre>
<h2>MinMaxScaler from sklearn</h2>
<p>Instead of writing our own feature scaler <del>we can</del> we should use the MinMaxScaler from sklearn. It works with numpy arrays by default.</p>
<pre>from sklearn.preprocessing import MinMaxScaler
import numpy as np

weights = np.array([[52.0], [79.0], [64.0]])
scaler = MinMaxScaler()
rescaled_weight = scaler.fit_transform(weights)
print(rescaled_weight)</pre>
<h2>Affected Algorithms</h2>
<p>Which algorithms are affected by non-properly scaled features?</p>
<p>SVM and k-means are algorithms which are affected. SVM for example calculates distances and when two features differ dramatically in value range, the feature with the greater range will dominate the other. (As seen when adding kilograms and meters)</p>
<p>The post <a href="https://creatronix.de/feature-scaling/">Feature Scaling</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
