Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 numpy import abs | |
from numpy import log | |
from numpy import sign | |
from scipy.stats import rankdata | |
# region Auxiliary functions | |
def ts_sum(df, window=10): | |
""" |
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 sklearn.metrics import log_loss, f1_score, accuracy_score | |
def ml_cross_val_score( | |
baseline_fn, | |
X: pd.DataFrame, | |
y: pd.Series, | |
cv_gen, | |
sample_weight_train: np.ndarray = None, | |
sample_weight_score: np.ndarray = None, | |
scoring = log_loss): |
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 sklearn.svm import SVC | |
from time import time | |
from sklearn.metrics import f1_score | |
def train_classifier(clf, X_train, y_train): | |
''' Fits a classifier to the training data. ''' | |
# Start the clock, train the classifier, then stop the clock | |
start = time() | |
clf.fit(X_train, y_train) |
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
_train_data, _test_data, _eval_data = create_dataset(['bitcoin.csv']) | |
print(_train_data.shape, _test_data.shape, _eval_data.shape) | |
train_scaler, train_data = scale_data(_train_data) | |
train_x, train_y = extract_features_labels(train_data) | |
test_scaler, test_data = scale_data(_test_data) | |
test_x, test_y = extract_features_labels(test_data) |
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 preprocessing(file): | |
_data = [] | |
print('Processing file ', file) | |
f = open(file, 'r') | |
try: | |
df = pd.read_csv(f, delimiter=',', usecols=['date', 'open', 'high', 'low', 'close']) | |
df = df.sort_values('date') | |
df = df.drop(['date'], axis=1) | |
dataset = df.values |
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
Datetime | Open | High | Low | Close | Volume | MarketCap | |
---|---|---|---|---|---|---|---|
2013-04-28T00:00:00 | 135.3 | 135.98 | 132.1 | 134.21 | 0 | 1500519936 | |
2013-04-29T00:00:00 | 134.44 | 147.49 | 134 | 144.54 | 0 | 1491160064 | |
2013-04-30T00:00:00 | 144 | 146.93 | 134.05 | 139 | 0 | 1597779968 | |
2013-05-01T00:00:00 | 139 | 139.89 | 107.72 | 116.99 | 0 | 1542819968 | |
2013-05-02T00:00:00 | 116.38 | 125.6 | 92.28 | 105.21 | 0 | 1292189952 | |
2013-05-03T00:00:00 | 106.25 | 108.13 | 79.1 | 97.75 | 0 | 1180070016 | |
2013-05-04T00:00:00 | 98.1 | 115 | 92.5 | 112.5 | 0 | 1089890048 | |
2013-05-05T00:00:00 | 112.9 | 118.8 | 107.14 | 115.91 | 0 | 1254759936 | |
2013-05-06T00:00:00 | 115.98 | 124.66 | 106.64 | 112.3 | 0 | 1289469952 |
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 __future__ import absolute_import, division, print_function | |
from math import sqrt | |
import numpy as np | |
import pandas as pd | |
import tensorflow as tf | |
from keras import Sequential, optimizers, metrics | |
from keras.layers import LSTM, Dropout, Dense | |
from keras.losses import mean_squared_error |
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
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
def xpath_soup(element): | |
""" | |
Generate xpath from BeautifulSoup4 element | |
:param element: BeautifulSoup4 element. | |
:type element: bs4.element.Tag or bs4.element.NavigableString | |
:return: xpath as string |