Kaggle competition: Natural Language Processing with Disaster Tweets
datas = [train,test]
for data in datas:
int_to_categorical(data)
 print(test.dtypes )<categorify>
logging.basicConfig(format='[%(asctime)s %(levelname)8s] %(message)s', level=logging.INFO, datefmt='%m-%d %H:%M:%S')
def creating_dummies(data):

 for column in categorical_column:
dummies = pd.get_dummies(data[column],prefix=column)
 data = pd.concat([data,dummies],axis =1)
 data.drop([column],axis=1,inplace= True )<categorify>
def transfrom(text_train, text_test):
large_use = 'https://tfhub.dev/google/universal-sentence-encoder-large/5'
embed = hub.load(large_use)
 vector_train = [tf.reshape(embed([line]), [-1] ).numpy() for line in tqdm(text_train)]
vector_test = [tf.reshape(embed([line]), [-1] ).numpy() for line in tqdm(text_test)]
return vector_train, vector_test
for column in categorical_column:
dummies = pd.get_dummies(train[column],prefix=column)
 train = pd.concat([train,dummies],axis =1)
 train.drop([column],axis=1,inplace= True)
 for column in categorical_column:
dummies = pd.get_dummies(test[column],prefix=column)
 test = pd.concat([test,dummies],axis =1)
 test.drop([column],axis=1,inplace= True)
 print(train.shape)
 print(test.shape )<compute_train_metric>
train = pd.read_csv('.. /input/nlp-getting-started/train.csv')
 test = pd.read_csv('.. /input/nlp-getting-started/test.csv')
 vector_train, vector_test = transfrom(train.text, test.text)
def gini(actual, pred, cmpcol = 0, sortcol = 1):
assert(len(actual)== len(pred))
all = np.asarray(np.c_[ actual, pred, np.arange(len(actual)) ], dtype=np.float)
 all = all[ np.lexsort(( all[:,2], -1*all[:,1])) ]
totalLosses = all[:,0].sum()
giniSum = all[:,0].cumsum().sum() / totalLosses
giniSum -=(len(actual)+ 1)/ 2.
 return giniSum / len(actual)
 def gini_normalized(a, p):
return gini(a, p)/ gini(a, a)
 def gini_xgb(preds, dtrain):
labels = dtrain.get_label()
gini_score = gini_normalized(labels, preds)
 return 'gini', gini_score<choose_model_class>
model = svm.SVC()
X_train, X_val, y_train, y_val = train_test_split(vector_train, train.target, test_size=0.2, random_state=2020)
 model.fit(X_train, y_train)
 preds = model.predict(X_val)
 print('Accuracy score', accuracy_score(y_val, preds))
print('f1_score', f1_score(y_val, preds))
<init_hyperparams><EOS> 
final_preds = model.predict(vector_test)
 sub = pd.read_csv(f".. /input/nlp-getting-started/sample_submission.csv")
 sub['target'] = final_preds
sub.to_csv('submission.csv', index=False)