Code Monkey home page Code Monkey logo

ds-normalizing-features's Introduction

Normalizing Features

You might have noticed that our previous model wasn't exactly stellar. This is because we missed a key technique used in machine learning: normalization. Normalizing features takes all of our data and fits variables to a similar scale and range. When we previously performed gradient descent, the budget and imdbVotes features had a much larger impact on our steps and the resulting output. That's not necessarily due to those features being more predictive of the gross domestic sales, but rather simply because the values of those features were much higher then the imdbRating or Metascore features which had much more narrow ranges. To account for this, we'll start normalizing our data, and transform back to the raw version when needed.

import pandas as pd
%matplotlib inline
df = pd.read_excel('movie_data_detailed_with_ols.xlsx')
df.head()
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; }
.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}
</style>
budget domgross title Response_Json Year imdbRating Metascore imdbVotes Model
0 13000000 25682380 21 &amp; Over 0 2008 6.8 48 206513 4.912759e+07
1 45658735 13414714 Dredd 3D 0 2012 0.0 0 0 2.267265e+05
2 20000000 53107035 12 Years a Slave 0 2013 8.1 96 537525 1.626624e+08
3 61000000 75612460 2 Guns 0 2013 6.7 55 173726 7.723381e+07
4 40000000 95020213 42 0 2013 7.5 62 74170 4.151958e+07

1. Basic Norm function

Write a function norm(col) that takes in a pandas series, and rescales the data to have a minimum of zero and a maximum of 1. Think about how you can do this by simply using the minimum and maximum of the column.

def norm(col):
    #Define your function here
    return None

2. Apply your norm function to the X feature columns

X = df[['budget', 'imdbRating',
       'Metascore', 'imdbVotes']]
y = df['domgross']
#Your code here

3. Try writing a slightly different normalization function: the mean normaliztion.

Here's how its defined:
mean_normalized_x = $\frac{x-mean(x)}{max(x)-min(x)}$

def norm(col):
    #Define your function here
    return None

ds-normalizing-features's People

Contributors

fpolchow avatar mathymitchell avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.