Skip to content

Instantly share code, notes, and snippets.

Avatar

Megha Agarwal megha444

  • India
View GitHub Profile
View matplot.py
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()
View pandas.py
import pandas as pd
ds=pd.read_csv('train.csv')
ds.head()
ds.shape()
View nltk.py
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))
View keras.py
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
View theano.py
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)
View scikit.py
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']]
View num.py
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)
View test.py
#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
View trainEvaluateTune.py
# function to train the model
def train():
model_def.train()
totalloss, totalaccuracy = 0, 0
# empty list to save model predictions
totalpreds=[]
View classImbalance.py
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
You can’t perform that action at this time.