<jupyter_start><jupyter_text>Explaining Feature Engineering  Basic questions<jupyter_code># Why is called feature engineering? Classifying data so machine can understand it.
# How do we do that? We make them binary. And create features.
# What is a feature? Featurea are based on attributes, wich help for predictions.<jupyter_output><empty_output><jupyter_text>An Example<jupyter_code>import pandas as pd
%matplotlib inline
from sklearn import preprocessing
df = pd.DataFrame({'key':['cat','cat','dog','donkey','dog','cat'],'data1':range(6)})
df<jupyter_output><empty_output><jupyter_text>Getting the dummies<jupyter_code>#data1
#key = attributes, and they can become the features for our pred model.
#Definition
#Dummy variables assign the numbers ‘0’ and ‘1’ to indicate membership in any mutually exclusive and exhaustive category.
#https://www.moresteam.com/whitepapers/download/dummy-variables.pdf
pd.get_dummies(df['key'],prefix='key')
billionaires = pd.read_excel('richpeople.xlsx')
billionaires.head(2)
#Doing the same with the billionaires
billionaires['Old Guys'] = billionaires['age'].apply(lambda x: 1 if x>60 else 0 )
#These are the billionaires above 70
Oldguys = billionaires[['name', 'age', 'Old Guys']]
Oldguys.head(2)
#Here we are telling the machine that in row 4 we have an age 0. Which is probably wrong.
pd.get_dummies(billionaires['age'],prefix='age')<jupyter_output><empty_output><jupyter_text>Multicollinearity<jupyter_code>#What does thar mean? Two values that are kind of dependent. BAsed on one you can predict the other. Highly correlated.
pd.get_dummies(billionaires['gender'],prefix='gender').corr()
#Why isnt this one?
pd.get_dummies(billionaires['selfmade'],prefix='selfmade').corr()
x = billionaires[['age','networthusbillion']].values
min_max_scaler = preprocessing.MinMaxScaler()
x_scaled = min_max_scaler.fit_transform(x)
df_normalized = pd.DataFrame(x_scaled)
x
billionaires_nonulls = billionaires[pd.notnull(billionaires['age'])]
x = billionaires_nonulls[['age','networthusbillion']].values
#Fitting between 1 - 0
min_max_scaler = preprocessing.MinMaxScaler()
x_scaled = min_max_scaler.fit_transform(x)
#Creating new dataframe
df_normalized = pd.DataFrame(x_scaled)
df_normalized
df_normalized.corr()
billionaires_nonulls.describe()<jupyter_output>/usr/local/lib/python3.5/site-packages/numpy/lib/function_base.py:3823: RuntimeWarning: Invalid value encountered in percentile
  RuntimeWarning)<jupyter_text>Why are we doing this?<jupyter_code>#So we don'r have any misrepresenations.

#Are we doing this, so that our classifications are as reliable as possible?<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11326491828202205, 'fraction_numerical': 0.008741923223109084, 'mean_word_length': 7.71523178807947, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 21, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '189281', 'license': 'MIT', 'n_tokens_mistral': 888, 'n_tokens_neox': 849, 'n_words': 224, 'path': '08 practice/Class Learning Feature Engineering.ipynb', 'repo_name': 'barjacks/algorithms_mine', 'size': '2631'}