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
for i in tqdm(range(1, 21)): | |
player = WebDriverWait(browser, 20).until(expected_conditions.visibility_of_element_located((By.XPATH, '//*[@id="rankingDetailAjaxContainer"]/table/tbody/tr['+str(i)+']/td[4]/a'))) | |
Tennis_data_collection.write(player.text + ',') | |
WebDriverWait(browser, 20).until(expected_conditions.visibility_of_element_located((By.XPATH, '//*[@id="rankingDetailAjaxContainer"]/table/tbody/tr['+str(i)+']/td[4]/a'))).click() | |
turned_pro = WebDriverWait(browser, 20).until(expected_conditions.visibility_of_element_located((By.XPATH, '//*[@id="playerProfileHero"]/div[2]/div[2]/div/table/tbody/tr[1]/td[2]/div/div[2]'))).text | |
career_length = 2019 - int(turned_pro) | |
Tennis_data_collection.write(str(career_length) + ',') | |
WebDriverWait(browser, 20).until(expected_conditions.visibility_of_element_located((By.XPATH, '//*[@id="profileTabs"]/ul/li[6]/a'))).click() |
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 matplotlib.pyplot as plt | |
from sklearn.datasets import make_classification | |
from sklearn.linear_model import LogisticRegression | |
from sklearn.model_selection import train_test_split | |
from sklearn.metrics import precision_recall_curve, auc | |
import seaborn as sns | |
X, y = make_classification(n_samples=1000, n_classes=2, random_state=1) | |
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=2) | |
model = LogisticRegression(solver='lbfgs') |
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 matplotlib.pyplot as plt | |
# ROC and AUC modules | |
from sklearn.datasets import make_classification | |
from sklearn.linear_model import LogisticRegression | |
from sklearn.model_selection import train_test_split | |
from sklearn.metrics import roc_curve, roc_auc_score | |
import seaborn as sns | |
# generate 2 class dataset | |
X, y = make_classification(n_samples=1000, n_classes=2, weights=[0.5], random_state=1) |
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
def meta_decorator(arg): | |
def decorator_list(fnc): | |
def inner(list_of_tuples): | |
return [(fnc(val[0], val[1])) ** power for val in list_of_tuples] | |
return inner | |
if callable(arg): | |
power = 2 | |
return decorator_list(arg) | |
else: | |
power = arg |
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
def integer_check(method): | |
def inner(ref, expo=None): | |
if expo == None: | |
if not isinstance(ref._val1, int) or not isinstance(ref._val2, int): | |
raise TypeError('Please enter numerical numbers for val1 and val2') | |
else: | |
return method(ref) | |
if expo: | |
if not isinstance(ref._val1, int) or not isinstance(ref._val2, int)\ | |
or not isinstance(expo, int): |
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 Decorators: Using Decorators with methods defined in a Class | |
def integer_check(method): | |
def inner(ref): | |
if not isinstance(ref._val1, int) or not isinstance(ref._val2, int): | |
raise TypeError('val1 and val2 must be integers') | |
else: | |
return method(ref) | |
return inner |
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 CustomIterTeams(object): | |
def __init__(self, division, teams=[]): | |
self._mng = division | |
self._teams = teams | |
self._index = -1 | |
def __iter__(self): | |
return self | |
# def __iter__(self): |
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
# __init__ method with a decorator | |
def attr_validation(method): | |
def inner(ref, name, age, location): | |
for attr in [name, location]: | |
if not isinstance(attr, str): | |
raise TypeError('Name and Location attributes must be of type str') | |
if not isinstance(age, int): | |
raise TypeError('Age attributes must be of type int') | |
return method(ref, name, age, location) | |
return inner |
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
e1 = Employees(46347832, 30, 'Bournemouth') | |
for key, value in e1.__dict__.items(): | |
print('{}: {}'.format(key, value)) | |
#Console output | |
TypeError: Only valid attributes of type string are accepted |
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, location): | |
self._name = name | |
self._age = age | |
self._location = location | |
def __setattr__(self, key, value): | |
if key in ['_name', '_location']: | |
if not isinstance(value, str): | |
raise TypeError('Only valid attributes of type string are accepted') |
NewerOlder