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
class DeletionException(Exception): | |
def __init__(self, original_value): | |
self._original_value = original_value | |
def __str__(self): | |
return 'The value for the name attribute, {} can not be deleted'.format(self._original_value) | |
class Employees(object): | |
def __init__(self, name, age, id_number): |
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
class Employees(object): | |
def __init__(self, name, age, id_number): | |
self._name = name | |
self._age = age | |
self._id_number = id_number | |
def __setattr__(self, key, value): | |
if key == '_name' and hasattr(self, '_name'): | |
raise AttributeError('The value for the name attribute has already been set, and can not be re-set') | |
if key in ['_age', '_id_number']: |
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
class Employees(object): | |
def __init__(self, name, age, id_number): | |
self._name = name | |
self._age = age | |
self._id_number = id_number | |
def __setattr__(self, key, value): | |
if key == '_name' and hasattr(self, '_name'): | |
raise AttributeError('The value for the name attribute has already been set, and can not be re-set') | |
if key in ['_age', '_id_number']: |
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
results =[] | |
strategies = ['mean', 'median', 'most_frequent','constant'] | |
for s in strategies: | |
pipeline = Pipeline([('impute', SimpleImputer(strategy=s)),('model', model)]) | |
cv = RepeatedStratifiedKFold(n_splits=10, n_repeats=3, random_state=1) | |
scores = cross_val_score(pipeline, X, y, scoring='accuracy', cv=cv, n_jobs=-1) | |
results.append(scores) |
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
dataframe.columns | |
dataframe = pd.read_csv('framingham.csv') | |
for i in range(len(dataframe.columns)): | |
missing_data = dataframe[dataframe.columns[i]].isna().sum() | |
perc = missing_data / len(dataframe) * 100 | |
print('>%d, missing entries: %d, percentage %.2f' % (i, missing_data, perc)) |
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 | |
import seaborn as sns | |
dataframe = pd.read_csv('framingham.csv') | |
dataframe.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
features = pd.DataFrame(data=data[0], columns=['feature_' + str(i) for i in range(1, 6)]) | |
lables = pd.DataFrame(data[1], columns=['labels']) | |
dataset = pd.concat([features, lables], axis=1) | |
data_point_1 = scaler.transform(np.array(dataset.iloc[0][:-1]).reshape(-1, 5)) | |
knn.predict(data_point_1)[0] | |
# Output | |
# 0 |
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.preprocessing import MinMaxScaler | |
scaler = MinMaxScaler() | |
X = scaler.fit_transform(df_feat) | |
from sklearn.model_selection import train_test_split | |
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=101) |
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
error_rate = [] | |
for i in range(1, 40): | |
knn = KNeighborsClassifier(n_neighbors=i) | |
knn.fit(X_train, y_train) | |
pred_i = knn.predict(X_test) | |
error_rate.append(np.mean(pred_i != y_test)) | |
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 selenium import webdriver | |
from selenium.webdriver.common.action_chains import ActionChains | |
from selenium.webdriver.common.keys import Keys | |
from selenium.webdriver.chrome.options import Options | |
from selenium.webdriver.support.wait import WebDriverWait | |
from selenium.webdriver.common.by import By | |
from selenium.webdriver.support import expected_conditions as EC | |
headless_options = Options() |