This file contains hidden or 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 matplotlib.pyplot as plt | |
def plot_graphs(history, string): | |
plt.plot(history.history[string]) | |
plt.plot(history.history['val_'+string]) | |
plt.xlabel("Epochs") | |
plt.ylabel(string) | |
plt.legend([string, 'val_'+string]) | |
plt.show() |
This file contains hidden or 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 zipfile import ZipFile | |
import os | |
from os.path import basename | |
def zip_dir(dirname, zipfilename): | |
with ZipFile(zipfilename, 'w') as zipObj: | |
# Iterate over all the files in directory | |
for folderName, subfolders, filenames in os.walk(dirname): | |
for filename in filenames: | |
#create complete filepath of file in directory |
This file contains hidden or 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 | |
import pandas as pd | |
from matplotlib.path import Path | |
import matplotlib.pyplot as plt | |
import matplotlib.patches as patches | |
import seaborn as sns | |
from typing import Union, List, Tuple | |
def parallel_coordinates(df: pd.DataFrame, |
This file contains hidden or 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
def top_10_accuracy(preds, train_data, is_higher_better=True): | |
y_preds = np.asarray(preds).reshape(-1, len(np.unique(y))) | |
y_true = train_data.get_label() | |
score = top_k_accuracy_score(y_true, y_preds, k=10) | |
return ('top_10_accuracy', score, True) |
This file contains hidden or 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 logging | |
from bisect import bisect | |
from logging import getLogger, Formatter, LogRecord, StreamHandler | |
from typing import Dict | |
class LevelFormatter(Formatter): | |
def __init__(self, formats: Dict[int, str], **kwargs): | |
super().__init__() |
This file contains hidden or 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 requests import get | |
from io import BytesIO | |
from zipfile import ZipFile | |
import os | |
from pathlib import Path | |
destination = "testproject" | |
file_url = 'https://github.com/vikramsoni2/aihubcli/archive/refs/heads/main.zip' |
This file contains hidden or 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
metrics_names = ['loss', 'accuracy', 'top10_accuracy'] | |
plt.figure(figsize=(14,4)) | |
sns.set_style('whitegrid') | |
for i in range(len(metrics_names)): | |
ax = plt.subplot(1, len(metrics_names), i+1) | |
ax.plot(history.history[metrics_names[i]], label="train") | |
ax.plot(history.history['val_'+ metrics_names[i]], label="valid") | |
ax.title.set_text(metrics_names[i]) | |
This file contains hidden or 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
contractions = { | |
"ain't": "am not", | |
"aren't": "are not", | |
"can't": "cannot", | |
"can't've": "cannot have", | |
"'cause": "because", | |
"could've": "could have", | |
"couldn't": "could not", | |
"couldn't've": "could not have", | |
"didn't": "did not", |
This file contains hidden or 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_true = le.inverse_transform(y_valid) | |
y_pred = le.inverse_transform(y_valid_pred_lr) | |
from sklearn.metrics import confusion_matrix | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
%matplotlib inline | |
data = confusion_matrix(y_true, y_pred) |