<jupyter_start><jupyter_text>Precision and Recall<jupyter_code>def precision_recall_calculation(predict, expected):

    print("=== Precision ===")
    print("Correct: ", np.sum(expected == predict))
    print("All data: ", expected.shape[0])
    precision = np.sum(expected == predict) / expected.shape[0]
    print("Precision: ", precision)
    
    correct = expected == predict

    print("\n=== Recall ===")
    print("Correct: ", np.sum(correct[expected == 1]))
    print("All data: ", np.sum(expected == 1))
    recall = np.sum(correct[expected == 1]) / np.sum(expected == 1)
    print("Recall: ", recall)
    
    print ("\n=== F1 ===")
    print("F1: ", 2 * precision * recall / (precision + recall))
    
precision_recall_calculation(
    np.zeros(data.shape[0]),
    data[:,2]
)
from sklearn.model_selection import train_test_split

x_train, x_test, y_train, y_test = np.asarray(train_test_split(data[:,0:2], data[:,2], test_size=0.3))<jupyter_output><empty_output><jupyter_text>Linear Regression ModelTry to train data with simple model<jupyter_code>from keras.models import Sequential
from keras.layers import Dense
from keras.optimizers import Adam

model = Sequential()
model.add(Dense(1, input_shape=(2,), kernel_initializer='uniform', activation='sigmoid'))
optimizer = Adam(lr=0.1)
model.compile(loss='binary_crossentropy', optimizer=optimizer)

model.summary()
model.fit(x_train, y_train, epochs=10, batch_size=2, verbose=1)
print(model.evaluate(x_test, y_test, batch_size=1))
plt.figure(figsize=(7,7))
y_predict = model.predict(x_test).reshape(-1)
y_predict = y_predict < 0.5
plt.scatter(x_test[y_predict, 0], x_test[y_predict, 1])
plt.scatter(x_test[y_predict == False, 0], x_test[y_predict == False, 1], color='C1')
plt.show()
precision_recall_calculation(
    (model.predict(x_test) > 0.5).astype(np.float64).reshape(-1),
    y_test
)<jupyter_output>=== Precision ===
Correct:  298
All data:  300
Precision:  0.993333333333

=== Recall ===
Correct:  35
All data:  37
Recall:  0.945945945946

=== F1 ===
F1:  0.969060670817
{'fraction_non_alphanumeric': 0.16430317848410758, 'fraction_numerical': 0.04449877750611247, 'mean_word_length': 5.3343653250774, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '397515', 'license': 'MIT', 'n_tokens_mistral': 802, 'n_tokens_neox': 739, 'n_words': 141, 'path': '07-precision-recall.ipynb', 'repo_name': 'neungkl/learn-ml-globish', 'size': '2045'}