text_plain_output_2.png text_plain_output_1.png
from sklearn.feature_extraction.text import CountVectorizer

from sklearn.linear_model import LogisticRegression

import numpy as np

import pandas as pd

train_dataset = pd.read_csv('../input/nlp-getting-started/train.csv')
test_dataset = pd.read_csv('../input/nlp-getting-started/test.csv')

train_dataset.shape

train_dataset.fillna('', inplace=True)
test_dataset.fillna('', inplace=True)

dataset = pd.DataFrame()
test_dataset_cleaned = pd.DataFrame()
dataset['all_combined'] = train_dataset['keyword'] + ' ' + train_dataset['location'] + ' ' + train_dataset['text']
test_dataset_cleaned['all_combined'] = test_dataset['keyword'] + ' ' + test_dataset['location'] + ' ' + test_dataset['text']
test_dataset_cleaned.shape

from sklearn.feature_extraction.text import CountVectorizer
vectorizer = CountVectorizer()
X = vectorizer.fit_transform(dataset['all_cleaned'])
X = X.toarray()
preparing_test_df = vectorizer.transform(test_dataset_cleaned['all_cleaned'])
preparing_test_df = preparing_test_df.toarray()

from sklearn.linear_model import LogisticRegression
X_train = np.array(X)
y_train = dataset['target']
X_test = np.array(preparing_test_df)
clf = LogisticRegression(solver='liblinear')
clf.fit(X_train, y_train)

prediction = clf.predict(X_test)

submission = pd.DataFrame({'id': test_dataset['id'], 'target': prediction})

submission.shape