Skip to content

Instantly share code, notes, and snippets.

Avatar

Stephen Fordham StephenFordham

View GitHub Profile
View testing_strategies.py
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)
View missing_cols_vals.py
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))
View imports.py
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()
View creating_a_datapoint.py
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
View scaling.py
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)
View error_rate.py
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))
View virus_headline_script.py
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()
View waits.py
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
search_box = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, 'input[id="orb-search-q"]')))
#search_box = driver.find_element_by_css_selector('input[id="orb-search-q"]')
View headless_browser.py
from selenium.webdriver.chrome.options import Options
headless_options = Options()
headless_options.add_argument('--headless')
driver = webdriver.Chrome(options=headless_options)
View iterate_through_headlines.py
top_titles = driver.find_elements_by_css_selector('div[class="css-14rwwjy-Promo ett16tt11"]')
with open('Coronavirus_headlines.txt', 'w') as cor_virus:
for title in top_titles:
headline = title.find_element_by_css_selector('p[class="css-1aofmbn-PromoHeadline ett16tt4"]').text
cor_virus.write('\n')
cor_virus.write(headline)
print(headline)
You can’t perform that action at this time.