<jupyter_start><jupyter_text>EXERCISE 3 - Deep Learning Class 2020.1**Professor** : <NAME> [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/jpvt/Deep_Learning/blob/main/Assignment_1/Exercise_3/Exercise_3.ipynb)  Importing libraries<jupyter_code>from data_generator import generate_losangles, generate_edges
import matplotlib.pyplot as plt
from sklearn.metrics import accuracy_score, confusion_matrix
from tail_scratch_nn import DNN
import numpy as np
import seaborn as sns
from sklearn.preprocessing import OneHotEncoder<jupyter_output><empty_output><jupyter_text>Generating data<jupyter_code>quadrants = [0,1,2,3]
data_train = []
data_test = []
amount_train = 500 # Amount of data per class
amount_test = 100
for quadrant in quadrants:
    data_train.extend(generate_losangles(amount_train,quadrant))
    data_test.extend(generate_losangles(amount_test,quadrant))
    data_train.extend(generate_edges(amount_train,quadrant))
    data_test.extend(generate_edges(amount_test,quadrant))
    
data_train = np.array(data_train)
data_test = np.array(data_test)
X_train = data_train[:,[0,1]]
y_train = data_train[:,2]
x_test = data_test[:,[0,1]]
y_test = data_test[:,2]<jupyter_output><empty_output><jupyter_text>Visualizing data<jupyter_code>plt.figure(figsize=(10,10))
plt.title('TRAIN SET')
plt.scatter(X_train[:,0], X_train[:,1], c = y_train)
plt.show()
plt.figure(figsize=(10,10))
plt.title('TEST SET')
plt.scatter(x_test[:,0], x_test[:,1], c = y_test)
plt.show()<jupyter_output><empty_output><jupyter_text>* OneHotEncoding our answers, so the softmax function can learn and predict with them.<jupyter_code>onehot = OneHotEncoder()
onehot = OneHotEncoder()
y_train = onehot.fit_transform(y_train.reshape(-1,1)).toarray()
y_test = onehot.fit_transform(y_test.reshape(-1,1)).toarray()<jupyter_output><empty_output><jupyter_text>***<jupyter_code>neural_net = DNN()
neural_net.fit(X_train.T, y_train.T, x_test.T, y_test.T, hidden="relu", output="softmax")
neural_net.train([2, 10, 10, 8], learning_rate=0.01, iterations=1000, adam_optimizer=True)
y_pred = neural_net.predict(x_test.T).T
np.argmax(y_pred, axis=1)
np.argmax(y_test, axis=1)
accuracy_score(np.argmax(y_test, axis=1), np.argmax(y_pred, axis=1))
cf_matrix = confusion_matrix(np.argmax(y_test, axis =1), np.argmax(y_pred,axis =1))
plt.figure(figsize=(8,8))
sns.heatmap(cf_matrix)
cf_matrix<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14198036006546644, 'fraction_numerical': 0.02536824877250409, 'mean_word_length': 8.44015444015444, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '598089', 'license': 'MIT', 'n_tokens_mistral': 976, 'n_tokens_neox': 935, 'n_words': 143, 'path': 'Assignment_1/Exercise_3/Exercise_3.ipynb', 'repo_name': 'jpvt/Deep_Learning', 'size': '2459'}