text_html_output_1.png
from sklearn.feature_extraction.text import TfidfVectorizer

from sklearn.linear_model import LogisticRegression

from sklearn.metrics import log_loss

from sklearn.preprocessing import MaxAbsScaler

import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

train = pd.read_csv('../input/train.csv')
test = pd.read_csv('../input/test.csv')

subm = pd.read_csv('../input/sample_submission.csv')

df = pd.concat([train['comment_text'], test['comment_text']], axis=0)
df = df.fillna('unknown')
nrow_train = train.shape[0]

vectorizer = TfidfVectorizer(stop_words='english', max_features=50000)
data = vectorizer.fit_transform(df)
X = MaxAbsScaler().fit_transform(data)
col = ['toxic', 'severe_toxic', 'obscene', 'threat', 'insult', 'identity_hate']
preds = np.zeros((test.shape[0], len(col)))

loss = []
for i, j in enumerate(col):
    model = LogisticRegression()
    model.fit(X[:nrow_train], train[j])
    preds[:, i] = model.predict_proba(X[nrow_train:])[:, 1]
    pred_train = model.predict_proba(X[:nrow_train])[:, 1]
    loss.append(log_loss(train[j], pred_train))
submid = pd.DataFrame({'id': subm['id']})
submission = pd.concat([submid, pd.DataFrame(preds, columns=col)], axis=1)

submission.head()