text_plain_output_1.png
from sklearn.ensemble import RandomForestClassifier

from sklearn.linear_model import LogisticRegression

from sklearn.metrics import classification_report

from sklearn.metrics import matthews_corrcoef

from sklearn.metrics import roc_curve

import matplotlib.pyplot as plt

import numpy as np

img_label = np.load('/content/drive/MyDrive/HMD_project/new/embedding_train_img_norm.npy')
txt_input = np.load('/content/drive/MyDrive/HMD_project/new/lsa_bow_train_text.npy')
img = img_label[:, 0:-1]
label = img_label[:, -1]
txt = txt_input
img_txt = np.concatenate((img, txt), axis=1)
x = img_txt
y = label
y.shape

img_label_val = np.load('/content/drive/MyDrive/HMD_project/new/embedding_val_img_norm.npy')
txt_input_val = np.load('/content/drive/MyDrive/HMD_project/new/lsa_bow_val_text.npy')
img_val = img_label_val[:, 0:-1]
label_val = img_label_val[:, -1]
txt_val = txt_input_val
img_txt_val = np.concatenate((img_val, txt_val), axis=1)
x_val = img_txt_val
y_val = label_val
x_val.shape

clf = LogisticRegression(max_iter=1000, C=0.1, penalty='l2')
clf.fit(x, y)
y_pred_p = clf.predict_proba(x)
b = y_pred_p[:, -1]
b = b.reshape(y.shape)
fpr, tpr, th = roc_curve(y, b)
optimal_idx = np.argmax(tpr - fpr)
optimal_threshold = th[optimal_idx]

y_pred = np.where(clf.predict_proba(x)[:, 1] > optimal_threshold, 1, 0)
y_pred_val = np.where(clf.predict_proba(x_val)[:, 1] > optimal_threshold, 1, 0)

clf = RandomForestClassifier(max_depth=3, random_state=0)
clf.fit(x, y)
y_pred_p = clf.predict_proba(x)
b = y_pred_p[:, -1]
b = b.reshape(y.shape)
fpr, tpr, th = roc_curve(y, b)
optimal_idx = np.argmax(tpr - fpr)
optimal_threshold = th[optimal_idx]

y_pred = np.where(clf.predict_proba(x)[:, 1] > optimal_threshold, 1, 0)
print(classification_report(y, y_pred))
print(matthews_corrcoef(y, y_pred))
print('\n\nvalidation')
y_pred_val = np.where(clf.predict_proba(x_val)[:, 1] > optimal_threshold, 1, 0)
print(classification_report(y_val, y_pred_val))
print(matthews_corrcoef(y_val, y_pred_val))