Horje
bag of word scikit learn Code Example
bag of word scikit learn
import numpy as np
import pandas as pd
from sklearn.feature_extraction.text import CountVectorizer

docs = ['Tea is an aromatic beverage..',
        'After water, it is the most widely consumed drink in the world',
        'There are many different types of tea.',
        'Tea has a stimulating effect in humans.',
        'Tea originated in Southwest China during the Shang dynasty'] 

df = pd.DataFrame({'sms_message': docs, 'label': np.random.choice([0, 1], size=5)})

cv = CountVectorizer()
counts = cv.fit_transform(df['sms_message'])

df_counts = pd.DataFrame(counts.A, columns=cv.get_feature_names())
df_counts['label'] = df['label']




Python

Related
automl classification tutorial sklearn Code Example automl classification tutorial sklearn Code Example
pandas not is na Code Example pandas not is na Code Example
convert float with missing values to integer Code Example convert float with missing values to integer Code Example
inverse of a matrix with determinant 0 python linalg Code Example inverse of a matrix with determinant 0 python linalg Code Example
decimal to octal in python Code Example decimal to octal in python Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7