Skip to content

Instantly share code, notes, and snippets.

View alik604's full-sized avatar
👨‍🎓
Full time student

K. Ali Pardhan alik604

👨‍🎓
Full time student
View GitHub Profile
# load data and set labels. details admitted
train = pd.read_csv('https://raw.githubusercontent.com/defcom17/NSL_KDD/master/KDDTrain%2B.csv')
test = pd.read_csv('https://raw.githubusercontent.com/defcom17/NSL_KDD/master/KDDTest%2B.csv')
train.columns , test.columns = labels , labels
combined_data = pd.concat([train, test]).drop('difficulty_level', 1)
le = LabelEncoder()
vector = combined_data['attack_type']
print("Attack Vectors:", set(list(vector))) # use print to make it print on single line
@alik604
alik604 / EEGNet.py
Last active December 25, 2019 21:44
EEGNet in Keras
def EEGNet(nb_classes, Chans = 64, Samples = 128,
dropoutRate = 0.5, kernLength = 64, F1 = 8,
D = 2, F2 = 16, norm_rate = 0.25, dropoutType = 'Dropout'):
""" Keras Implementation of EEGNet
http://iopscience.iop.org/article/10.1088/1741-2552/aace8c/meta
Inputs:
nb_classes : int, number of classes to classify
Chans, Samples : number of channels and time points in the EEG data
import pylab as plt
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import keras
from keras.models import Sequential, Model
from keras.layers import Dense
from keras.optimizers import Adam
# https://github.com/alik604/Notebooks/blob/master/Data%20Science-Datasets/MNIST/Where_to_add_GaussianNoise_MNIST_.ipynb
# data - MNIST
# note - test_size=0.98... ya...
model = Sequential()
model.add(Conv2D(filters=100, kernel_size=3)) # remove relu
# model.add(GaussianNoise(0.5)) # sandwich between
# GaussianNoise(0.5) here - accuracy: 0.9829 - val_loss: 0.4050 - val_accuracy: 0.9024
model.add(Activation('relu')) # add relu
# GaussianNoise(0.5) here - accuracy: 0.9900 - val_loss: 1.4703 - val_accuracy: 0.8073
model.add(MaxPooling2D(pool_size=(2, 2)))
@alik604
alik604 / OpenCV_Image_Augmentation.py
Created June 4, 2020 16:25
Image augmentation by mirroring, random rotation, shifts, shear and flips, etc.
# @credit - kaggle.com/hanzh0420/image-augmentation-with-opencv
import os
print(os.listdir("../input"))
# Input data files are available in the "../input/" directory.
# Any results you write to the current directory are saved as output.
import numpy as np
#import pandas as pd # pd.read_csv
import cv2
import random
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@alik604
alik604 / boilerplate.py
Last active July 1, 2020 00:34
boiler plate for jupyter notebook on Data Science or Machine Learning
%%capture
!pip install scikit-plot
!pip install catboost
!pip install mlxtend
!pip install yfinance
!pip install pyod
import pyod
import yfinance
import xgboost # xgboost.readthedocs.io/en/latest/python/python_api.html#xgboost.XGBClassifier
@alik604
alik604 / visualizing data in 2d and 3d.py
Last active October 24, 2023 22:40
Quickly visualize your data in 2d and 3d with PCA and TSNE (t-sne)
# imports from matplotlib import pyplot as plt
from matplotlib import pyplot as plt
import pylab
from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.mplot3d import proj3d
%matplotlib inline
%pylab inline
from sklearn.manifold import TSNE
from sklear.decomposition import PCA
@alik604
alik604 / build_dataset LSTM.py
Created July 28, 2020 01:17
build_dataset LSTM.py
# make dataset to input
def build_dataset(time_series, seq_length):
dataX = []
dataY = []
for i in range(0, len(time_series) - seq_length):
_x = time_series[i:i + seq_length, :]
_y = time_series[i + seq_length, [-1]] # Next close price
print(_x, "->", _y)
dataX.append(_x)
dataY.append(_y)
import urllib.parse as parse
url = ""
if 'url' not in globals():
print("Enter URL to parse")
url = input()
def printDict(data):
for x in data: