# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# +
import os, platform, pprint, sys
# import fastai
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import sklearn


seed: int = 14


# set up pretty printer for easier data evaluation
pretty = pprint.PrettyPrinter(indent=4, width=30).pprint


# declare file paths for the data we will be working on
file_path_1: str = '../../data/ddos/DDoS_vs_Benign_10000.csv'
file_path_2: str = '../../data/ddos/DDoS_vs_Benign_50000.csv'
dataPath   : str = './models'


# print library and python versions for reproducibility
print(
    f'''
    python:\t{platform.python_version()}

    \tmatplotlib:\t{mpl.__version__}
    \tnumpy:\t\t{np.__version__}
    \tpandas:\t\t{pd.__version__}
    \tsklearn:\t{sklearn.__version__}
    '''
)


# -

def load_data(filePath: str) -> pd.DataFrame:
    '''
        Loads the Dataset from the given filepath and caches it for quick access in the future
        Function will only work when filepath is a .csv file
    '''

    # slice off the ./CSV/ from the filePath
    if filePath[0] == '.' and filePath[1] == '.':
        filePathClean: str = filePath[11::]
        pickleDump: str = f'../../data/cache/{filePathClean}.pickle'
    else:
        pickleDump: str = f'../../data/cache/{filePath}.pickle'
    
    print(f'Loading Dataset: {filePath}')
    print(f'\tTo Dataset Cache: {pickleDump}\n')
    
    # check if data already exists within cache
    # if not, load data and cache it
    if os.path.exists(pickleDump):
        df = pd.read_pickle(pickleDump)
    else:
        df = pd.read_csv(filePath, low_memory=True)
        df.to_pickle(pickleDump)
    
    return df


df = load_data(file_path_1)

df.shape

X = df.values[:, :-1]

y = df.values[:,-1:]

X,y

I = np.array([.3,.84])
vec = np.array([np.sqrt(2),np.sqrt(1.5)])
m0 = np.array([0, 0, 1, 1, 1])
W=np.array([[np.sqrt(2), .34,.12,.01,.41],
            [.23,np.sqrt(1.2),.4,.5,np.sqrt(2.2)]])
B=np.array([.1,.2,.3,.11,.24])
M = np.diag(m0)

a = np.matmul(W,M)

np.matmul(I,a)+np.matmul(B,M)

I*vec

np.dot(I, vec)

m0*W

a

m0*B

np.matmul(B,M)


def f(x):
    return 1/(1+np.exp(x))


f(np.matmul(I,a))+np.matmul(B,M)



StarcoderdataJupyterScriptsDedupFiltered