<jupyter_start><jupyter_text>There is not a big different between 0.4, 0.5, 0.6<jupyter_code>df_train = pd.DataFrame( x_train[:, :, :, 0].reshape(x_train[:, :, :, 0].shape[0], 28*28))
df_train["label"] = y_train
# df_test = pd.DataFrame( x_test[:, :, :, 0].reshape(x_test[:, :, :, 0].shape[0], 28*28))
# df_test["label"] = y_test

# df = pd.concat([df_train, df_test])
# df.reset_index(inplace=True, drop=True)
X_train = df_train.drop(['label'], axis=1)
y_train = df_train['label']
# Random Shifts
from keras.datasets import mnist
from keras.preprocessing.image import ImageDataGenerator
from matplotlib import pyplot


# shifting

(X_train, y_train), (X_test, y_test) = mnist.load_data()
X_train = X_train.reshape((X_train.shape[0], 28, 28, 1))
X_test = X_test.reshape((X_test.shape[0], 28, 28, 1))
# convert from int to float
X_train = X_train.astype('float32')
X_test = X_test.astype('float32')
# define data preparation<jupyter_output><empty_output><jupyter_text>Example on how you can import our python class. Dont forget to run the first cell!<jupyter_code>from preprocess.get_data import aquire_data

# todo: allow unnormalized data
data_preprocess_params = {
    "threshold": True,
    "normalize": True,
    "augment_data": {"rotate": True, "shift": True, "zoom": True, "shear": True, "all": True},
}
# function return generator. does not do any manipulations on the test set

train, test = aquire_data(**data_preprocess_params)


# stop the iterator after certain iterations 
"""
for x,y in stop_iterator(train, 300):
    # your code
    

"""
for i,(x, y) in enumerate(train):
    plt.imshow(x.reshape(28, 28))
    plt.title(y)
    plt.colorbar()
    plt.show()
    break<jupyter_output><empty_output><jupyter_text>MLP Model<jupyter_code>class GradientDescent:    
    def __init__(self, learning_rate=.001, max_iters=1e4, epsilon=1e-8):
        self.learning_rate = learning_rate
        self.max_iters = max_iters
        self.epsilon = epsilon
        
    def run(self, gradient_fn, x, y, params):
        norms = np.array([np.inf])
        t = 1
        while np.any(norms > self.epsilon) and t < self.max_iters:
            grad = gradient_fn(x, y, params)
            for p in range(len(params)):
                params[p] -= self.learning_rate * grad[p]
            t += 1
            norms = np.array([np.linalg.norm(g) for g in grad])
        return params


class MLP:
    def __init__(self, activation_fnc, weight, bias, n_hidden_layers=2, n_units_hidden_layers=64):
        self.activation_fnc = activation_fnc
        self.n_hidden_layers = n_hidden_layers
        self.n_units_hidden_layers = n_units_hidden_layers
        self.weight = weight
        self.bias = bias

    def fit(self, X_train, y_train, learning_rate, n_iter):
        """"
        input of x_train is 1x784 column matrix
        
        
        output layer is 10 big for the 10 numbers (0 to 9)
        """
        pass

    def predict(self, X_test, y_test):
        pass<jupyter_output><empty_output><jupyter_text>Run experiments<jupyter_code>sigmoid = lambda x: x+1
tanh = lambda x: x-1
relu = lambda x: x**2

MLP_params = {
    "activation_fnc": lambda x: x + 1,
    "weight": 20000,
    "bias": 0.001,
    "n_hidden_layers": 2,
    "n_units_hidden_layers": 64,
}


MLP_params_signmoid_low_weight = {
    "activation_fnc": lambda x: x + 1,
    "weight": 200,
    "bias": 0.001,
    "n_hidden_layers": 2,
    "n_units_hidden_layers": 64,
}



train, test = aquire_data(**data_preprocess_params)
model = MLP(**MLP_params)
model.fit(1, 2, 3, 4)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13094571908226077, 'fraction_numerical': 0.027140458869613877, 'mean_word_length': 3.542566709021601, 'pattern_counts': {'":': 18, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '562547', 'license': 'MIT', 'n_tokens_mistral': 1384, 'n_tokens_neox': 1300, 'n_words': 303, 'path': 'mini-project-3/notebook/notebook.ipynb', 'repo_name': 'ding-ma/applied-ml', 'size': '3574'}