Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

feature engineering data preprocessing

from sklearn.preprocessing import StandardScaler

num_vars = ['pickup_lon', 'pickup_lat', 'dropoff_lon', 'dropoff_lat', 'distance']
cat_vars = ['hour', 'day', 'region']

scaler = StandardScaler()
scaler.fit(train[num_vars])

def design_matrix(t):
    """Create a design matrix from taxi ride dataframe t."""
    scaled = t[num_vars].copy()
    scaled.iloc[:,:] = scaler.transform(scaled) # Convert to standard units
    categoricals = [pd.get_dummies(t[s], prefix=s, drop_first=True) for s in cat_vars]
    return pd.concat([scaled] + categoricals, axis=1)

design_matrix(train).iloc[0,:]  
Comment

PREVIOUS NEXT
Code Example
Python :: how to convert string into list in python 
Python :: how to compare list and int in python 
Python :: a function to create a null matrix in python 
Python :: python sort a list using defined order 
Python :: python debugging 
Python :: pca in python 
Python :: find index of value in list python 
Python :: count TRUE in DF 
Python :: how to check how many key value pairs are in a dict python 
Python :: how add a favicon to django 
Python :: python upload file to s3 
Python :: python regex split 
Python :: {"message": "401: Unauthorized", "code": 0} discord 
Python :: what does the combinations itertools in python do 
Python :: Python DateTime Class Syntax 
Python :: dataframe select row by index value 
Python :: atoi in python code 
Python :: picture plot 
Python :: linkedlist python 
Python :: how to create a new dataframe in python 
Python :: upgrade python version windows 
Python :: refer dataframe with row number and column name 
Python :: datetime conversion 
Python :: python print every row of dataframe 
Python :: run ipython inside pipenv 
Python :: gamma distribution python normalized 
Python :: python ravel function 
Python :: numpy column 
Python :: @ in python 
Python :: tanh activation function 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =