Data Pre-processing using Scikit-learn

from sklearn.preprocessing import StandardScalernumeric_columns = [c for c in data.columns if data[c].dtype != np.dtype('O')]
temp_data = data[numeric_columns]
standard_scaler = StandardScaler()
standardized_data = standard_scaler.fit_transform(temp_data)
pd.DataFrame(standardized_data , columns = temp_data.columns)
from sklearn.preprocessing import MinMaxScalernormalizer = MinMaxScaler()
normalized_data = normalizer.fit_transform(temp_data)
pd.DataFrame(normalized_data , columns = temp_data.columns)
from sklearn.preprocessing import LabelEncoderle = LabelEncoder()
data['Status'] = le.fit_transform(data['Status'])
data['Status'].value_counts()
one_hot = OneHotEncoder()
transformed_data = one_hot.fit_transform(data['race/ethnicity'].values.reshape(-1,1)).toarray()
one_hot.categories_transformed_data = pd.DataFrame(transformed_data ,columns = ['math score', 'reading score'])
transformed_data.head()transformed_data.iloc[90 , ]data['race/ethnicity'][90]

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Use Grafana to Present Epidemic Data

Building The Analytics Team At Wish Part 3— Scaling Data Analysis

Classify the imbalanced time series data with RNN

The First Signs of Alcoholic Liver Damage Are Not in the Liver

Applying linear regression to a wine data set

Quantitative Trading 101

Tennis Serve Analyzer Expert System (Part 2)

USA Road Accidents — Hot Spots and Severity

America Accidents’ Hot Spots

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
PRASHIL VAISHNANI

PRASHIL VAISHNANI

student

More from Medium

Importance of data preprocessing and fine-tuning

Getting started with EDA and Feature Engineering

5 Core Steps to Understand Machine Learning Workflow — a Guide for beginners

Simplifying Machine Learning , Part-1 Linear Regression