Kaggle competition: Bad comments
<SOS> metric: mcauc Kaggle data source: bad-comments<load_from_csv>
train = pd.read_csv('.. /input/train.csv')
 test = pd.read_csv('.. /input/test.csv')
image_set = pd.read_csv('.. /input/test.csv')
 for i in np.random.randint(28001, size=10):
print("Predicted : " + str(predict_array[i]))
image = image_set.iloc[i].values.reshape(28, 28)
 plt.imshow(image, cmap='gray')
 plt.show()<save_to_csv>
class_names = ['toxic', 'severe_toxic', 'obscene', 'threat', 'insult', 'identity_hate']
train_text = train['comment_text']
test_text = test['comment_text']
all_text = pd.concat([train_text, test_text])
 word_vectorizer = TfidfVectorizer(
 sublinear_tf=True,
strip_accents='unicode',
analyzer='word',
token_pattern=r'\w{1,}',
stop_words='english',
ngram_range=(1, 1),
max_features=10000)
 word_vectorizer.fit(all_text)
 train_word_features = word_vectorizer.transform(train_text)
 test_word_features = word_vectorizer.transform(test_text)
 char_vectorizer = TfidfVectorizer(
 sublinear_tf=True,
strip_accents='unicode',
analyzer='char',
stop_words='english',
ngram_range=(2, 5),
max_features=50000)
 char_vectorizer.fit(all_text)
 train_char_features = char_vectorizer.transform(train_text)
 test_char_features = char_vectorizer.transform(test_text)
 train_features = hstack([train_char_features, train_word_features])
 test_features = hstack([test_char_features, test_word_features])
data_to_submit = pd.DataFrame({
'ImageId': range(1, 28001),
'Label': predict_array
})
 data_to_submit.to_csv('csv_to_submit3.csv', index = False )<set_options>
from sklearn.svm import LinearSVC
from sklearn.ensemble import AdaBoostClassifier
from sklearn.calibration import CalibratedClassifierCV
%matplotlib inline 
<load_from_csv>
scores = []
submission = pd.DataFrame.from_dict({'id': test['id']})
 for class_name in class_names:
train_target = train[class_name]
classifier = LogisticRegression(solver='sag')
 cv_score = np.mean(cross_val_score(classifier, train_features, train_target, cv=3, scoring='roc_auc'))
scores.append(cv_score)
 print('CV score for class {} is {}'.format(class_name, cv_score))
classifier.fit(train_features, train_target)
 submission[class_name] = classifier.predict_proba(test_features)[:, 1]
print('Total CV score is {}'.format(np.mean(scores)))
gender_submission = pd.read_csv(".. /input/titanic/gender_submission.csv")
 test = pd.read_csv(".. /input/titanic/test.csv")
 train = pd.read_csv(".. /input/titanic/train.csv" )<feature_engineering>
")