<commit_before>import db
from ctrades import trades
from pandas import Series, DataFrame
import matplotlib.pyplot as plt

from sklearn import svm

def binary(df, column_name):
	df['binary'] = df[column_name].pct_change()/abs(df[column_name].pct_change())
	return df

def split(ts, perc):
	inum = int(len(ts.index)*perc)
	index = ts['timestamp'].iloc[inum]
	ts1 = ts[ts['timestamp'] <= index]
	ts2 = ts[ts['timestamp'] > index]
	return ts1, ts2

trd = trades()
trd.add('trades', exchange='btcchina')
print 'Trades loaded'
trd.time_series(3600)
print 'Time series created'
ts = trd.ts
ts2, ts1 = split(ts, 0.25) 
ts1 = binary(ts1, 'price')
print('split')
price = ts1['price'].values
amount = ts1['amount'].values
data = zip(price, amount)
print('zip')
result = ts1['binary'].values

mach = svm.SVC()
mach.fit(data, result)

#price = ts2['price'].values
#amount = ts2['amount'].values
#data = zip(price, amount)

pred = mach.predict(data)
print 'pred'
data = zip(price, pred*1300)
df = DataFrame(data, index=ts1.index)
print df
#ts2['prediction'] = series
df.plot()
plt.show()<commit_msg>plots!<commit_after>import db
from ctrades import trades
from pandas import Series, DataFrame
import matplotlib.pyplot as plt

from sklearn import svm

def binary(df, column_name):
	df['binary'] = df[column_name].pct_change()*200.0/abs(df[column_name].pct_change())
	df['binary'] = df['binary'].shift(-1)
	return df

def split(ts, perc):
	inum = int(len(ts.index)*perc)
	index = ts['timestamp'].iloc[inum]
	ts1 = ts[ts['timestamp'] <= index]
	ts2 = ts[ts['timestamp'] > index]
	return ts1, ts2

def plot2D(df):
	df = df.drop('amount', axis=1)	
	df.plot()
	plt.show()

trd = trades()
trd.add('trades', exchange='bitfinex')
print 'Trades loaded'
trd.time_series(3600)
print 'Time series created'
ts = trd.ts
ts1, ts2 = split(ts, 0.25) 
ts1 = binary(ts1, 'price')
print('split')
price = ts1['price'].values
amount = ts1['amount'].values
data = zip(price, amount)
print('zip')
result = ts1['binary'].values

mach = svm.SVC()
mach.fit(data, result)

price = ts2['price'].values
amount = ts2['amount'].values
pred = mach.predict(data)
data = zip(price, amount, pred)
df = DataFrame(data, index=ts2.index, columns=('price','amount','pred'))
plot2D(df)


{'fraction_non_alphanumeric': 0.17570596145226355, 'fraction_numerical': 0.024652622142536978, 'mean_word_length': 5.743202416918429, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6366529', 'n_tokens_mistral': 878, 'n_tokens_neox': 854, 'n_words': 202}