text_html_output_1.png
from sklearn.ensemble import ExtraTreesClassifier

from sklearn.feature_extraction.text import TfidfVectorizer

from sklearn.metrics import accuracy_score

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')
sub = pd.read_csv('../input/sample_submission.csv')

train.shape

test.shape

train.dtypes

test.dtypes

test.fillna('missing', inplace=True)

target_labels = ['toxic', 'severe_toxic', 'obscene', 'threat', 'insult', 'identity_hate']

X = train.comment_text
test_X = test.comment_text

from sklearn.feature_extraction.text import CountVectorizer
from sklearn.feature_extraction.text import TfidfVectorizer
vect = TfidfVectorizer(max_features=50000, min_df=2)

X_dtm = vect.fit_transform(X)

test_X_dtm = vect.transform(test_X)

from sklearn.metrics import accuracy_score
from sklearn.ensemble import ExtraTreesClassifier
etc = ExtraTreesClassifier(n_jobs=-1, random_state=3)

for label in target_labels:
    print('... Processing {}'.format(label))
    y = train[label]
    etc.fit(X_dtm, y)
    y_pred_X = etc.predict(X_dtm)
    print('Training accuracy is {}'.format(accuracy_score(y, y_pred_X)))
    test_y_prob = etc.predict_proba(test_X_dtm)[:, 1]
    sub[label] = test_y_prob