Skip to content

Instantly share code, notes, and snippets.

View megha444's full-sized avatar

Megha Agarwal megha444

  • Montreal, Canada
View GitHub Profile
from matplotlib import pyplot as pt
x = [7,12,3]
y = [1,16,6]
pt.plot(x,y)
pt.title('Info')
pt.ylabel('Y axis')
pt.xlabel('X axis')
pt.show()
import pandas as pd
ds=pd.read_csv('train.csv')
ds.head()
ds.shape()
import nltk
from nltk.tokenize import word_tokenize
nltk.download ('punkt')
text = "This is a sample text to show word tokenization"
print(word_tokenize(text))
import keras
from keras.layers import Dense, Activation
from keras.models import Sequential
import matplotlib.pyplot as plt
import numpy as np
xx = ipdata = np.linspace(1,2,100)
yy = xx*4 + np.random.randn(*xx.shape) * 0.3
import theano
from theano import tensor
m = tensor.dscalar()
n = tensor.dscalar()
p = a + b
q = theano.function([m,n], p)
r = q(1.5, 2.5)
print (r)
import numpy as np
from sklearn.preprocessing import MinMaxScaler
demo = np.random.randint(10, 200, (20 ,2))
scalarModel = MinMaxScaler()
scalarModel.fit_transform(demo)
scalarModel = MinMaxScaler()
featureData = scalarModel.fit_transform(demo)
import pandas as pan
data = pan.DataFrame(data=featureData, columns=['c1', 'c2', 'c3', 'label'])
X = data[['c1', 'c2', 'c3']]
import numpy as np
#Array object creation
num_array = np.array( [[3,2,1],
[7,1,5]] )
# Printing array object type
print("Array type is: ", type(num_array))
#Array dimensions
print("Number of dimensions: ", num_array.ndim)
@megha444
megha444 / test.py
Last active October 10, 2020 07:04
#load weights of best model
pathw = 'saved_weights.pt'
model_def.load_state_dict(torch.load(pathw))
#FINE TUNE FOR TEST DATA
# get predictions for test data
with torch.no_grad():
pred = model_def(testseq.to(device), testmask.to(device))
pred = pred.detach().cpu().numpy()
#TO CHECK MODEL PERFORMANCE
# function to train the model
def train():
model_def.train()
totalloss, totalaccuracy = 0, 0
# empty list to save model predictions
totalpreds=[]
from sklearn.utils.class_weight import compute_class_weight
#compute class weights
classw = compute_class_weight('balanced', np.unique(train_labels), trainlabels)
print("Class Weights:",classweights)
#Output obtained: [0.57743559 3.72848948]
# converting list of class weights to a tensor