Generation

generate functionMon, 27 Mar 2023

There is a dataframe df with two columns: Category and Message in the following format: Category Message 0 ham Go until jurong point, crazy... Available only ... 1 ham Ok lar... Joking wif u oni... 2 spam Free entry in 2 a wkly comp to win FA Cup fina... 3 ham U dun say so early hor... U c already then say... 4 ham Nah I don't think he goes to usf, he lives aro... Split it into samples X = df['Message'] y = df['Category'] so that there are float numbers instead of object text everywhere.

import pandas as pd import numpy as np df = pd.DataFrame({'Category':['ham','ham','spam','ham','ham'], 'Message':['Go until jurong point, crazy... Available only ...','Ok lar... Joking wif u oni...','Free entry in 2 a wkly comp to win FA Cup fina...','U dun say so early hor... U c already then say...','Nah I don\'t think he goes to usf, he lives aro...']}) df['Category'] = df['Category'].map(lambda x : 1 if x == 'ham' else 0)

Questions about programming?Chat with your personal AI assistant