Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

sklearn columntransformer

from sklearn.compose import ColumnTransformer
from sklearn.pipeline import Pipeline
from sklearn.impute import SimpleImputer
from sklearn.preprocessing import OneHotEncoder

# Preprocessing for numerical data
numerical_transformer = SimpleImputer(strategy='mean')

# Preprocessing for categorical data
categorical_transformer = Pipeline(steps=[
    ('Categorical_Imputer', SimpleImputer(strategy='most_frequent')),
    ('One_Hot_Encoder', OneHotEncoder(handle_unknown='ignore'))
])

# Bundle preprocessing for numerical and categorical data
preprocessor = ColumnTransformer(
    transformers=[
        ('Numerical_Transformer', numerical_transformer, numerical_cols),
        ('Categorical_Transformer', categorical_transformer, categorical_cols)
    ])
Comment

PREVIOUS NEXT
Code Example
Python :: python convert latitude longitude to x y 
Python :: python numpy array check if all nans 
Python :: pandas shift column 
Python :: colab tqdm import 
Python :: python randomized selection 
Python :: how to get data in treeview in tkiter 
Python :: python hour from date 
Python :: python read file without newline 
Python :: tkinter draw circle 
Python :: upgrade python to 3.8 
Python :: how to change voice of pyttsx3 
Python :: save dataframe to csv without index 
Python :: update python 3.10 ubuntu 
Python :: python repeating scheduler 
Python :: pandas dataframe show one row 
Python :: how to check if a string ends with a substring python 
Python :: iterate over rows dataframe 
Python :: area of a circle in python 
Python :: rotate labels matplotlib 
Python :: how to check suffix in python 
Python :: how to order randomly in django orm 
Python :: pandas select percentile 
Python :: sort list of dictionaries by key python 
Python :: ndarray to list 
Python :: how to read zip csv file in python 
Python :: pandas sort columns by name 
Python :: python html to pdf 
Python :: sum of a column in pandas 
Python :: find sum of values in a column that corresponds to unique vallues in another coulmn python 
Python :: for idx, col_name in enumerate(X_train.columns): print("The coefficient for {} is {}".format(file_name, regression_model.coef_[0][idx])) 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =