Skip to content

Instantly share code, notes, and snippets.

View mempirate's full-sized avatar

Jonas Bostoen mempirate

  • Antwerp, Belgium
  • 15:21 (UTC +02:00)
  • X @mempirate
View GitHub Profile
def handle_data(context, data):
RSI_periods = 14
context.i += 1
if context.i < RSI_periods:
return
RSI_data = data.history(context.asset,
"price",
def initialize(context):
context.asset = symbol("btc_usd")
context.i = 0
context.base_price = None
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from logbook import Logger
from math import floor, ceil
from catalyst import run_algorithm
from catalyst.api import order_target_percent, record, symbol
from catalyst.exchange.utils.stats_utils import extract_transactions
new_prediction = regressor.predict(1.5)
# Visualizing the test set results
plt.figure(figsize = (12, 6))
plt.scatter(X_test, y_test, alpha = 0.4, label = 'Observation Points')
plt.plot(X_train, regressor.predict(X_train), color = 'green', lw = 0.7, alpha = 0.8, label = 'Best Fit Line')
plt.title('Linear Regression (Test Set)')
plt.xlabel('Years of Experience')
plt.ylabel('Salary')
plt.legend()
# Visualizing the training set results
plt.figure(figsize = (12, 6))
plt.scatter(X_train, y_train, alpha = 0.4, label = 'Observation Points')
plt.plot(X_train, regressor.predict(X_train), color = 'green', lw = 0.7, alpha = 0.8, label = 'Best Fit Line')
plt.title('Linear Regression (Training Set)')
plt.xlabel('Years of Experience')
plt.ylabel('Salary')
plt.legend()
from sklearn.linear_model import LinearRegression
regressor = LinearRegression()
regressor.fit(X_train, y_train)
# Creating the matrix of features and the vector of labels
X = df.iloc[:, :-1].values
y = df.iloc[:, 1].values
# Dividing data up into training sets and test sets
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 1/3)
Random starting synaptic weights: Synaptic weights after training:
[-0.16595599] [ 9.67299303]
[ 0.44064899] [-0.2078435 ]
[-0.99977125] [-4.62963669]
Output after training:
[0.00966449]
[0.99211957]