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 | |
import numpy as np | |
import matplotlib.pyplot as plt | |
%matplotlib inline |
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
data_file_path = 'diabetes.csv' | |
data_df = pd.read_csv(data_file_path) | |
data_df.head() |
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
train_score = [] | |
test_score = [] | |
k_vals = [] | |
for k in range(1, 21): | |
k_vals.append(k) | |
knn = KNeighborsClassifier(n_neighbors = k) | |
knn.fit(X_train, y_train) | |
tr_score = knn.score(X_train, y_train) |
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 | |
nltk.download('punkt') | |
from nltk.tokenize import word_tokenize | |
import numpy as np |
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
!pip3 install --upgrade tensorflow-gpu | |
# Install TF-Hub. | |
!pip3 install tensorflow-hub |
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 models import InferSent | |
import torch | |
V = 2 | |
MODEL_PATH = 'encoder/infersent%s.pkl' % V | |
params_model = {'bsize': 64, 'word_emb_dim': 300, 'enc_lstm_dim': 2048, | |
'pool_type': 'max', 'dpout_model': 0.0, 'version': V} | |
model = InferSent(params_model) | |
model.load_state_dict(torch.load(MODEL_PATH)) |
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 sentence_transformers import SentenceTransformer | |
sbert_model = SentenceTransformer('bert-base-nli-mean-tokens') |
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
y_pred_proba = knn.predict_proba(X_test)[:,1] | |
fpr, tpr, thresholds = roc_curve(y_test, y_pred_proba) |
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 nltk.tokenize import word_tokenize | |
# Tokenization of each document | |
tokenized_sent = [] | |
for s in sentences: | |
tokenized_sent.append(word_tokenize(d.lower())) | |
tokenized_sent |
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
# Add our data-augmentation parameters to ImageDataGenerator | |
train_datagen = ImageDataGenerator(rescale = 1./255., rotation_range = 40, width_shift_range = 0.2, height_shift_range = 0.2, shear_range = 0.2, zoom_range = 0.2, horizontal_flip = True) | |
test_datagen = ImageDataGenerator(rescale = 1.0/255.) | |
train_generator = train_datagen.flow_from_directory(train_dir, batch_size = 20, class_mode = 'binary', target_size = (224, 224)) | |
validation_generator = test_datagen.flow_from_directory( validation_dir, batch_size = 20, class_mode = 'binary', target_size = (224, 224)) |
OlderNewer