PYTHON PROGRAM TO DEMONSTARTE LABEL ENCODING..

Поделиться
HTML-код
  • Опубликовано: 22 июн 2024
  • #PYTHON PROGRAM TO DEMONSTARTE LABEL ENCODING
    LABEL ENCODING : converting categorical data to numerical data
    import numpy as np
    import pandas as pd
    from sklearn import preprocessing
    Import dataset
    df = pd.read_csv('C:\Vinuthna\python_enthu\Iris.csv')
    print(df['species'].unique())
    #Encode the Labels in Species Column
    label_encoder = preprocessing.LabelEncoder()
    df['species']= label_encoder.fit_transform(df['species'])
    print("After Encoding")
    print(df['species'].unique())
    OUTPUT:
    ['setosa' 'versicolor' 'virginica']
    After Encoding
    [0 1 2]

Комментарии •