This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
ds=pd.read_csv('train.csv') | |
ds.head() | |
ds.shape() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# function to train the model | |
def train(): | |
model_def.train() | |
totalloss, totalaccuracy = 0, 0 | |
# empty list to save model predictions | |
totalpreds=[] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
NewerOlder