“Étiquette Encoding en Python” Réponses codées

étiqueter l'encodeur Python

from sklearn.preprocessing import LabelEncoder
encoder = LabelEncoder()

# apply on df
df['status'] = encoder.fit_transform(df['status'])
# can allso use the pandas.map
df['status'] = df['status'].map(lambda x: 1 if x=='Placed' else 0)

#apply on np.array
ct = ColumnTransformer(transformers=[('encoder', OneHotEncoder(), [1])], remainder='passthrough')
X = np.array(ct.fit_transform(X))
Adventurous Addax

Encodage d'étiquette

from sklearn.preprocessing import LabelEncoder

le = LabelEncoder()
companydata.ShelveLoc = le.fit_transform(companydata.ShelveLoc)
Condemned Cowfish

transformer les variables catégorielles python

from sklearn.preprocessing import LabelEncoder

lb_make = LabelEncoder()
obj_df["make_code"] = lb_make.fit_transform(obj_df["make"])
obj_df[["make", "make_code"]].head(11)
Lively Lobster

Étiquette Encoding en Python

##We apply Label Encoding on black Friday dataset on the target column which is Species. It contains three species Iris-setosa, Iris-versicolor, Iris-virginica. 

# Import libraries
import numpy as np
import pandas as pd
 
# Importing dataset
df = pd.read_csv('../../data/blackFriday.csv')

#Cheking out the unique values in your dataset
df['Age'].unique()

# Import label encoder
from sklearn import preprocessing
 
# label_encoder object knows how to understand word labels.
label_encoder = preprocessing.LabelEncoder()
 
# Encode labels in column 'Age'.
df['Age']= label_encoder.fit_transform(df['Age'])
 
df['Age'].unique()
DON-PECH

comment utiliser le codage d'étiquette en python


obj_df["body_style"] = obj_df["body_style"].astype('category')
obj_df.dtypes

obj_df["body_style_cat"] = obj_df["body_style"].cat.codes
obj_df.head()
Drab Dove

Réponses similaires à “Étiquette Encoding en Python”

Questions similaires à “Étiquette Encoding en Python”

Plus de réponses similaires à “Étiquette Encoding en Python” dans Python

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code