konstantgr/themisto huggingface dataset:
user_daily_actions = df.groupby(['user_id', pd.Grouper(key='action_time', freq='D')])['action_name'].count().reset_index()
user_total_actions = user_daily_actions.groupby('user_id')['action_name'].sum().reset_index()
top_users = user_total_actions.nlargest(int(0.2*len(user_total_actions)), 'action_name')['user_id']
df_top_users = df[df['user_id'].isin(top_users)]

df_top_users = df_top_users.set_index('action_time')
daily_counts = df_top_users.resample('D').count()


sns.lineplot(data=daily_counts, x=index, y='action_name', linewidth=0.5, legend=False)

#plt.plot(daily_counts.index, daily_counts['action_name'], '-o')

plt.show()
user_daily_actions = df.groupby(['user_id', pd.Grouper(key='action_time', freq='D')])['action_name'].count().reset_index()
user_total_actions = user_daily_actions.groupby('user_id')['action_name'].sum().reset_index()
top_users = user_total_actions.nlargest(int(0.2*len(user_total_actions)), 'action_name')['user_id']
df_top_users = df[df['user_id'].isin(top_users)]

df_top_users = df_top_users.set_index('action_time')
daily_counts = df_top_users.resample('D').count()


sns.lineplot(data=daily_counts, x=daily_counts.index, y='action_name', linewidth=0.5, legend=False)

#plt.plot(daily_counts.index, daily_counts['action_name'], '-o')

plt.show()
df_top_users = df[df['user_id'].isin(top_users)]

df_top_users = df_top_users.set_index('action_time')
daily_counts = df_top_users.resample('W').count()

sns.lineplot(data=daily_counts, x=daily_counts.index, y='action_name', linewidth=0.5, legend=False)

plt.show()
repeats = 0

for session_num, session_df in df.groupby(['user_id', 'session_num']):
    repeated_actions = session_df['action_name'].rolling(window=3).apply(lambda x: x[0] == x[1] == x[2])
    if repeated_actions.any():
        repeats += 1

repeats / df['session_num'].nunique()
df['action_name'] = pd.Categorical(df['action_name'])
# Reading the data from a text file and saving to Pandas DataFrame
with zipfile.ZipFile('data/task1/jetnet_logs.zip') as myzip:
    with myzip.open('jetnet_logs.txt') as myfile:
        df = pd.read_csv(myfile, delimiter='\t', header=None)
df = df[df['action_name'] != 'END']
df = df[df['action_name'] != 'null']
df.dropna(how='any', inplace=True)
df = df.reset_index(drop=True)
# The resulting dataset is as follows
df
# Each user has different number of actions.
pd.DataFrame(df.groupby('user_id')['action_time'].count()).sample(n=10)
df['date'] = df['action_time'].dt.date

df.groupby('date').size()
df['date'] = df['action_time'].dt.date
stats = df.groupby('date').size()
stats
df['date'] = df['action_time'].dt.weekday
stats = df.groupby('date').size()
stats
df['date'] = df['action_time'].dt.date
stats = df.groupby('date').size()
stats['day_of_week'] = df['action_time'].dt.dayofweek
stats
df['date'] = df['action_time'].dt.date
stats = df.groupby('date').size()
#stats['day_of_week'] = df['action_time'].dt.dayofweek
stats
df['date'] = df['action_time'].dt.date
stats = pd.DataFrame(df.groupby('date').size())
#stats['day_of_week'] = df['action_time'].dt.dayofweek
stats
df['date'] = df['action_time'].dt.date
stats = pd.DataFrame(df.groupby('date').size())
stats['day_of_week'] = df['action_time'].dt.dayofweek
stats
df['date'] = df['action_time'].dt.date
df['day_of_week'] = df['action_time'].dt.dayofweek
stats = pd.DataFrame(df.groupby('date').size())
stats['day_of_week'] = df['day_of_week']
stats
df['date'] = df['action_time'].dt.date
df['day_of_week'] = df['action_time'].dt.dayofweek
#stats = pd.DataFrame(df.groupby('date').size())
#stats['day_of_week'] = df['day_of_week']
#stats
df
df['date'] = df['action_time'].dt.date
df['day_of_week'] = df['action_time'].dt.dayofweek
stats = pd.DataFrame(df.groupby('date').size())
#stats['day_of_week'] = df['day_of_week']
#stats
stats
df['date'] = df['action_time'].dt.date
df['day_of_week'] = df['action_time'].dt.dayofweek
stats = pd.DataFrame(df.groupby('date').size())
stats['day_of_week'] = df.index.dt.dayofweek
#stats
stats
df['date'] = df['action_time'].dt.date
df['day_of_week'] = df['action_time'].dt.dayofweek
df
df.groupby('date').size()
df.groupby('day_of_week').size()
df.groupby('day_of_week').size().reset_index(name='count')
df.groupby(['day_of_week'])['date'].rank(method='dense').astype(int)
pd.crosstab(df['day_of_week'], df.groupby(['day_of_week'])['date'].rank(method='dense').astype(int))
data = pd.crosstab(df['day_of_week'], df.groupby(['day_of_week'])['date'].rank(method='dense').astype(int))
data
f_statistic, p_value = stats.f_oneway(*data)

print("F-statistic:", f_statistic)
print("p-value:", p_value)
f_statistic, p_value = stats.f_oneway(data)

print("F-statistic:", f_statistic)
print("p-value:", p_value)
data[0]
data.iloc[0]
data.iloc[0].to_list
data.iloc[0].to_list()
f_statistic, p_value = stats.f_oneway(data.iloc[0].to_list(),data.iloc[1].to_list(),data.iloc[2].to_list(),data.iloc[3].to_list(),data.iloc[4].to_list(),data.iloc[5].to_list()data.iloc[6].to_list())

print("F-statistic:", f_statistic)
print("p-value:", p_value)
f_statistic, p_value = stats.f_oneway(data.iloc[0].to_list(),data.iloc[1].to_list(),data.iloc[2].to_list(),data.iloc[3].to_list(),data.iloc[4].to_list(),data.iloc[5].to_list(), data.iloc[6].to_list())

print("F-statistic:", f_statistic)
print("p-value:", p_value)
f_statistic, p_value = stats.f_oneway(data.iloc[0].to_list(),data.iloc[1].to_list(),data.iloc[2].to_list(),data.iloc[3].to_list(),data.iloc[4].to_list(),data.iloc[5].to_list(), data.iloc[6].to_list())

print("p-value:", p_value)
data.T.boxplot()
t_stat, p_val = stats.ttest_ind(data.iloc[0].to_list()+data.iloc[1].to_list()+data.iloc[2].to_list()+data.iloc[3].to_list()+data.iloc[4].to_list(),data.iloc[5].to_list()+data.iloc[6].to_list())
print("p-value:", p_value)
t_stat, p_val = stats.ttest_ind(data.iloc[0].to_list()+data.iloc[1].to_list()+data.iloc[2].to_list()+data.iloc[3].to_list()+data.iloc[4].to_list(),data.iloc[5].to_list()+data.iloc[6].to_list())
print("p-value:", p_val)
session_durations = df.groupby(['user_id', 'session_num'])['action_time'].apply(lambda x: x.max() - x.min())

mean_duration = session_durations.mean()
median_duration = session_durations.median()
mode_duration = session_durations.mode()[0]

print(f"Mean: {mean_duration}")
print(f"Median: {median_duration}")
print(f"Mode: {mode_duration}")
session_durations = df.groupby(['user_id', 'session_num'])['action_time'].apply(lambda x: x.max() - x.min())

mean_duration = session_durations.mean()
median_duration = session_durations.median()
mode_duration = session_durations.mode()[0]

print(f"Mean: {mean_duration}")
print(f"Median: {median_duration}")
grouped = df.sort_values(['user_id', 'session_num', 'action_time']).groupby(['user_id', 'session_num'])['action_name']
counts = grouped.apply(lambda x: x.value_counts().sort_index().rolling(2).apply(lambda y: y[0]*y[1], raw=True).sum()).reset_index(name='count')
matrix = counts.pivot(index='action_name', columns='action_name', values='count').fillna(0)
sns.heatmap(matrix, cmap='coolwarm')
plt.show()
df['prev_action'] = df.groupby(['user_id', 'session_num'])['action_name'].shift(1)
counts = df.groupby(['prev_action', 'action_name']).size().reset_index(name='count')
pivot_counts = counts.pivot_table(index='prev_action', columns='action_name', values='count', fill_value=0)
sns.heatmap(pivot_counts, cmap='YlGnBu')
df['prev_action'] = df.groupby(['user_id', 'session_num'])['action_name'].shift(1)
counts = df.groupby(['prev_action', 'action_name']).size().reset_index(name='count')
pivot_counts = counts.pivot_table(index='prev_action', columns='action_name', values='count', fill_value=0)
sns.heatmap(pivot_counts, nnot=True, fmt=".1f")
df['prev_action'] = df.groupby(['user_id', 'session_num'])['action_name'].shift(1)
counts = df.groupby(['prev_action', 'action_name']).size().reset_index(name='count')
pivot_counts = counts.pivot_table(index='prev_action', columns='action_name', values='count', fill_value=0)
sns.heatmap(pivot_counts, annot=True, fmt=".1f")
session_durations = df.groupby(['user_id', 'session_num'])['action_time'].agg(lambda x: x.max() - x.min())
fig, ax = plt.subplots()
for user_id in session_durations.index.get_level_values(0).unique():
    durations = session_durations[user_id]
    ax.plot(durations.index, durations, label=f'User {user_id}')
ax.set_xlabel('Session Number')
ax.set_ylabel('Session Duration')
plt.show()
session_durations = df.groupby(['user_id', 'session_num'])['action_time'].agg(lambda x: x.max() - x.min())
fig, ax = plt.subplots()
for user_id in session_durations.index.get_level_values(0).unique():
    durations = session_durations[user_id]
    ax.plot(durations.index, durations)
ax.set_xlabel('Session Number')
ax.set_ylabel('Session Duration')
plt.show()
action_durations = df.groupby(['action_name', 'session_num'])['action_time'].agg(lambda x: x.max() - x.min())

fig, ax = plt.subplots()

for session_num in action_durations.index.get_level_values(1).unique():
    durations = action_durations.loc[:, session_num]
    ax.bar(durations.index, durations, label=f'Session {session_num}')

ax.set_xlabel('Action Name')
ax.set_ylabel('Action Duration (seconds)')
ax.legend()

plt.show()
# Do not forget to check if your notebook log collection plugin is working
df['date'] = df['action_time'].dt.date
df['day_of_week'] = df['action_time'].dt.dayofweek
user_daily_actions = df.groupby(['user_id', pd.Grouper(key='action_time', freq='D')])['action_name'].count().reset_index()
user_total_actions = user_daily_actions.groupby('user_id')['action_name'].sum().reset_index()
top_users = user_total_actions.nlargest(int(0.2*len(user_total_actions)), 'action_name')['user_id']
df_top_users = df[df['user_id'].isin(top_users)]

df_top_users = df_top_users.set_index('action_time')
daily_counts = df_top_users.resample('D').count()

sns.lineplot(data=daily_counts, x=daily_counts.index, y='action_name', linewidth=0.5, legend=False)

plt.show()
action_counts = df.groupby("action_name")["user_id"].count().reset_index(name="count")

sns.set(style="whitegrid")
sns.barplot(x="action_name", y="count", data=action_counts)
plt.xticks(rotation=70)
plt.tight_layout()
plt.show()
df_top_users = df[df['user_id'].isin(top_users)]

df_top_users = df_top_users.set_index('action_time')
daily_counts = df_top_users.resample('D').count()

sns.lineplot(data=daily_counts, x=daily_counts.index, y='action_name', linewidth=0.5, legend=False)

plt.show()
user_daily_actions = df.groupby(['user_id', pd.Grouper(key='action_time', freq='D')])['action_name'].count().reset_index()
user_total_actions = user_daily_actions.groupby('user_id')['action_name'].sum().reset_index()
top_users = user_total_actions.nlargest(int(0.2*len(user_total_actions)), 'action_name')['user_id']
print(1)
print(22)
train_features.text
train_features.aply(len)
from matplotlib import pyplot as plt
plt.hist(train_features.apply(len))
plt.hist(train_features.text.apply(len))
plt.hist(train_features.text.apply(len), log=True)
plt.hist(train_features.text.apply(len), log=True, bins=75);
plt.hist(train_features.text.apply(len), log=True, bins=75);
plt.title('distribution of the text lengths');
y_columns = [`load_data`, `helper_functions`, `data_preprocessing`, `data_exploration`, `modelling`, `prediction`, `evaluation`,
`result_visualization`, `save_results`, `comment_only`]
y_columns = ['load_data', 'helper_functions', 'data_preprocessing', 'data_exploration', 
             'modelling', 'prediction', 'evaluation',
             'result_visualization', 'save_results', 'comment_only']
train_features.primary_label
y_columns = ['load_data', 'helper_functions', 'data_preprocessing', 'data_exploration', 
             'modelling', 'prediction', 'evaluation',
             'result_visualization', 'save_results', 'comment_only']
y_column = ['primary_label']
set(train_features.columns) - set(y_column) - set(y_columns)
y_columns = ['load_data', 'helper_functions', 'data_preprocessing', 'data_exploration', 
             'modelling', 'prediction', 'evaluation',
             'result_visualization', 'save_results', 'comment_only']
y_column = ['primary_label']
X_columns = set(train_features.columns) - set(y_column) - set(y_columns)
!pip install sklearn
from sklearn.ensemble import RandomForestClassifier
train_features.filename
set(train_features.filename) & set(validation_features.filename)
y_columns = ['load_data', 'helper_functions', 'data_preprocessing', 'data_exploration', 
             'modelling', 'prediction', 'evaluation',
             'result_visualization', 'save_results', 'comment_only']
y_column = ['primary_label']
X_columns = set(train_features.columns) - set(y_column) - set(y_columns) - {'filename'}
rfclf = RandomForestClassifier()
train_features[X_columns]
train_features[X_columns]['packages_info']
train_features[X_columns]['packages_info'].apply(len)
train_features['cell_type']
train_features['cell_type'].value_counts()
train_features['cell_type'].value_counts(), validation_features['cell_type'].value_counts()
train_features['cell_type'].value_counts(), validation_features['cell_type'].value_counts() #🤔
# Config of the data types defining how to further process it for different trainings
y_columns = ['load_data', 'helper_functions', 'data_preprocessing', 'data_exploration', 
             'modelling', 'prediction', 'evaluation',
             'result_visualization', 'save_results', 'comment_only']
y_column = ['primary_label']
X_columns = set(train_features.columns) - set(y_column) - set(y_columns) - {'filename', 'cell_type'}
X_columns_text = {'packages_info', 'code_line_after', 'code_line_before', 'text', 'comment', 'markdown_heading'}
train_features[X_columns].values()
train_features[X_columns].values
train_features[y_columns]
train_features[y_columns].values.sum(1).mean()
plt.hist(train_features[y_columns].values.sum(1), bins=7, log=True);
plt.title('distribution of the classes count for the multiclass task')
plt.hist(train_features[y_columns].values.sum(1), bins=[-0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5], log=True);
plt.title('distribution of the classes count for the multiclass task')
plt.hist(train_features[y_columns].values.sum(1), bins=[-0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5], log=True);
plt.title('distribution of the classes count for the multiclass task');
train_features[y_column]
train_features[y_column].values
np.where(train_features[y_column].values, train_features[y_column].unique)
np.where(train_features[y_column].values, train_features.primary_label.unique)
np.where(train_features[y_column].values, train_features.primary_label.unique.values)
np.where(train_features[y_column].values, train_features.primary_label.unique())
train_features.primary_label.unique()
train_features[y_column].values = train_features.primary_label.unique().reshape(1, -1)
train_features[y_column].values == train_features.primary_label.unique().reshape(1, -1)
(train_features[y_column].values == train_features.primary_label.unique().reshape(1, -1)).np.where
(train_features[y_column].values == train_features.primary_label.unique().reshape(1, -1)).shape
{k: i for i, k in enumerate(train_features.primary_label.unique())}
# Config of the data types defining how to further process it for different trainings
y_columns = ['load_data', 'helper_functions', 'data_preprocessing', 'data_exploration', 
             'modelling', 'prediction', 'evaluation',
             'result_visualization', 'save_results', 'comment_only']
y_column = ['primary_label']
X_columns = set(train_features.columns) - set(y_column) - set(y_columns) - {'filename', 'cell_type'}
X_columns_text = {'packages_info', 'code_line_after', 'code_line_before', 'text', 'comment', 'markdown_heading'}
class_map = {k: i for i, k in enumerate(train_features.primary_label.unique())}
np.vectorize(class_map.get)(train_features[y_column].values)
train_features[X_columns-X_columns_text]
train_features[X_columns_text]
train_features[X_columns_text].applymap(len)
train_features[X_columns_text].applymap(lambda x: len(x) if not isinstance(x, int))
train_features[X_columns_text].applymap(lambda x: len(x) if not isinstance(x, int) else x)
def prepare_dataset_RF(df):
    y_multi = df[y_columns].values
    y_primary = np.vectorize(class_map.get)(train_features[y_column].values)
    X_numeric = df[X_columns - X_columns_text]
    X_text = df[X_columns_text]
    X_numeric_texts = X_text.applymap(lambda x: len(x) if not isinstance(x, int) else x)
    return pd.merge(X_numeric, X_numeric_texts, left_index=True, right_index=True), y_multi, y_primary
prepare_dataset_RF(train_features)
X_train, y_train_multi, y_train_primary = prepare_dataset_RF(train_features)
rfclf.fit(X_train, y_train_primary)
X_train, y_train_multi, y_train_primary = prepare_dataset_RF(train_features)
X_eval, y_eval_multi, y_eval_primary = prepare_dataset_RF(eval_features)
X_train, y_train_multi, y_train_primary = prepare_dataset_RF(train_features)
X_val, y_val_multi, y_val_primary = prepare_dataset_RF(validation_features)
rfclf.predict(X_val)
y_val_primary
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import f1_score
f1_score(y_val_primary, rfclf.predict(X_val))
def prepare_dataset_RF(df):
    y_multi = df[y_columns].values
    y_primary = np.vectorize(class_map.get)(df[y_column].values)
    X_numeric = df[X_columns - X_columns_text]
    X_text = df[X_columns_text]
    X_numeric_texts = X_text.applymap(lambda x: len(x) if not isinstance(x, int) else x)
    return pd.merge(X_numeric, X_numeric_texts, left_index=True, right_index=True), y_multi, y_primary
f1_score(y_val_primary, rfclf.predict(X_val), average=None)
f1_score(y_train_primary_primary, rfclf.predict(X_train), average=None)
f1_score(y_train_primary, rfclf.predict(X_train), average=None)
rfclf = RandomForestClassifier(min_samples_leaf=100)
rfclf = RandomForestClassifier(min_samples_leaf=10)
f1_score(y_val_primary, rfclf.predict(X_val), average='micro')
f1_score(y_val_primary, rfclf.predict(X_val), average='macro')
rfclf = RandomForestClassifier(min_samples_leaf=20)
rfclf = RandomForestClassifier(min_samples_leaf=5)
rfclf = RandomForestClassifier(min_samples_leaf=1)
rfclf = RandomForestClassifier(min_samples_leaf=10, max_depth=10)
rfclf = RandomForestClassifier(min_samples_leaf=10, max_depth=20)
rfclf = RandomForestClassifier(min_samples_leaf=10, max_depth=30)
validation_features[y_column]
validation_features[y_column].value_counts()
class_map
from tokenize import generate_tokens
train_features['text']
train_features['text'][0]
generate_tokens(train_features['text'][0])
[i for i in generate_tokens(train_features['text'][0])]
[i for i in generate_tokens(iter(train_features['text'][0]))]
from tokenize import generate_tokens
from functools import partial
with open('README.md') as f:
    print(len(f.readlines()))
with open('README.md') as f:
    for i in range(70):
    print(f.readline())
with open('README.md') as f:
    for i in range(70):
        print(f.readline())
class Readliner:
    def __init__(self, text_lines):
        self.text_lines = text_lines
        self.i = 0
    def __call__(self):
        if i < len(self):
            ctxt = self.text_lines[self.i]
            self.i += 1
            return ctxt
        return None
[i for i in generate_tokens(Readliner(train_features['text'][0]))]
class Readliner:
    def __init__(self, text_lines):
        self.text_lines = text_lines
        self.i = 0
        
    def __call__(self):
        if i < len(self):
            ctxt = self.text_lines[self.i]
            self.i += 1
            return ctxt
        return None
    
    def __len__(self):
        return len(self.text_lines)
class Readliner:
    def __init__(self, text_lines):
        self.text_lines = text_lines
        self.i = 0
        
    def __call__(self):
        if i < len(self):
            ctxt = self.text_lines[self.i]
            self.i += 1
            return ctxt
        return ''
    
    def __len__(self):
        return len(self.text_lines)
Readliner(train_features['text'][0])
Readliner(train_features['text'][0])()
class Readliner:
    def __init__(self, text_lines):
        self.text_lines = text_lines
        self.i = 0
        
    def __call__(self):
        if self.i < len(self):
            ctxt = self.text_lines[self.i]
            self.i += 1
            return ctxt
        return ''
    
    def __len__(self):
        return len(self.text_lines)
[i for i in generate_tokens(Readliner(train_features['text'][0]))][0]
[i for i in generate_tokens(Readliner(train_features['text'][0]))][0].string
[i.string for i in generate_tokens(Readliner(train_features['text'][0]))]
tokenize_py = lambda txt: [i.string for i in generate_tokens(Readliner(txt))]
class Readliner:
    def __init__(self, text_lines):
        self.text_lines = text_lines
        self.i = 0
        
    def __call__(self):
        if self.i < len(self):
            ctxt = self.text_lines[self.i]
            self.i += 1
            return ctxt
        return ''
    
    def __len__(self):
        return len(self.text_lines)

tokenize_py = lambda txt: [i.string for i in generate_tokens(Readliner(txt))]
from sklearn.feature_extraction.text import CountVectorizer
CountVectorizer(tokenizer=tokenize_py)
cv = CountVectorizer(tokenizer=tokenize_py)
train_features['text'].values
cv.fit(train_features['text'].values)
cv = CountVectorizer(tokenizer=tokenize_py, lowercase=False)
# empty cell
for txt in train_features['text'].values:
    tokenize_py(txt)
print(txt)
[i for i in Readliner(txt)]
[Readliner(txt)() for i in range(len(txt))]
krdl = Readliner(txt)
[krdl() for i in range(len(krdl))]
tokenize_py(txt[:1])
tokenize_py(txt[:2])
tokenize_py(txt[:3])
tokenize_py(txt[:4])
tokenize_py(txt[:5])
tokenize_py(txt[:6])
tokenize_py(txt[:7])
tokenize_py(txt[:8])
tokenize_py(txt[:9])
tokenize_py(txt[:10])
tokenize_py(txt[:11])
txt[:11]
txt[:12]
train_features.loc(1)
train_features.loc[1]
class Readliner:
    def __init__(self, text_lines):
        self.text_lines = text_lines
        self.i = 0
        
    def __call__(self):
        if self.i < len(self):
            ctxt = self.text_lines[self.i]
            self.i += 1
            return ctxt
        return ''
    
    def __len__(self):
        return len(self.text_lines)

def tokenize_py(txt):
    try:
        return [i.string for i in generate_tokens(Readliner(txt))]
    except:
        return ['fehler']
class Readliner:
    def __init__(self, text_lines):
        self.text_lines = text_lines
        self.i = 0
        
    def __call__(self):
        if self.i < len(self):
            ctxt = self.text_lines[self.i]
            self.i += 1
            return ctxt
        return ''
    
    def __len__(self):
        return len(self.text_lines)

def tokenize_py(txt):
    try:
        return [i.string for i in generate_tokens(Readliner(txt))]
    except:
        return ['Fehler']
cv.transform(train_features['text'][0])
cv.transform(train_features['text'][[0]])
cv.transform(train_features['text'][[1]])
cv.transform(train_features['text'][[2]])
cv.transform(train_features['text'][[3]])
cv.transform(train_features['text'][[4]])
cv.transform(train_features['text'][[10]])
text_counts = cv.transform(train_features['text'].values)
from sklearn.feature_extraction.text import TfidfTransformer

tf_transformer = TfidfTransformer(use_idf=False).fit(text_counts)
tf_transformer.transform(text_counts)
from sklearn.naive_bayes import MultinomialNB

clf = MultinomialNB().fit(tf_transformer.transform(text_counts), y_train_primary)
y_train_primary
from sklearn.naive_bayes import MultinomialNB

clf = MultinomialNB().fit(tf_transformer.transform(text_counts), y_train_primary.squeeze())
clf.predict(tf_transformer.transform(text_counts[0]))
clf.predict(tf_transformer.transform(text_counts[1]))
clf.predict(tf_transformer.transform(text_counts[2]))
clf.predict(tf_transformer.transform(text_counts[3]))
clf.predict(tf_transformer.transform(text_counts))
nb_prd = clf.predict(tf_transformer.transform(text_counts))
nb_prd = clf.predict(tf_transformer.transform(cv.transform(validation_features['text'].values)))
f1_score(y_val_primary, nb_prd, average=None)
nb_prd = clf.predict(tf_transformer.transform(cv.transform(train_features['text'].values)))
f1_score(y_train_primary, nb_prd, average=None)
nb_prd
clf.predict_proba(tf_transformer.transform(cv.transform(train_features['text'].values)))
tf_transformer = TfidfTransformer().fit(text_counts)
clf = MultinomialNB().fit(tf_transformer.transform(text_counts), y_train_primary.squeeze())