# Path: speculator/market.py
# TARGET_CODES = {'bearish': 0, 'neutral': 1, 'bullish': 2}
#         DIRECTION = 'last'
#     TARGET_NAMES = {v: k for k, v in TARGET_CODES.items()}
# class Market:
#     def __init__(self, json=None, symbol='USDT_BTC', unit='month', count=6, period=86400):
#     def get_json(self):
#     def set_features(self, partition=1):
#     def set_long_features(self, features, columns_to_set=[], partition=2):
# def set_targets(x, delta=10):
# def eval_features(json):
# def target_code_to_name(code):
# def setup_model(x, y, model_type='random_forest', seed=None, **kwargs):


from speculator import market
# Create the random forest model
# The last entry doesn't have a target (can't predict yet), so skip over it
model = market.setup_model(x[:-1], y, model_type='random_forest', seed=1,
                           n_estimators=65, n_jobs=4)

# Predict the target test set from the features test set
trends = model._predict_trends(model.features.test)

# Get accuracies
ftr_imps = model.feature_importances()
conf_mx = model.confusion_matrix(model.targets.test, trends)
acc = model.accuracy(model.features.test, model.targets.test)

# Display accuracies
print('##################')
print('# TEST SET       #')
print('##################')
print('Accuracy: {0:.3f}%'.format(100 * acc))
print('\nConfusion Matrix:')
print(conf_mx)
print(market.TARGET_CODES)
print('\nFeature Importance:')
for ftr, imp in ftr_imps:
    print('  {0}: {1:.3f}%'.format(ftr, 100 * imp))

print()

# Display prediction and probabilities for the next trend
print('##################')
print('# PREDICTED NEXT #')

# Path: speculator/market.py
# TARGET_CODES = {'bearish': 0, 'neutral': 1, 'bullish': 2}
#         DIRECTION = 'last'
#     TARGET_NAMES = {v: k for k, v in TARGET_CODES.items()}
# class Market:
#     def __init__(self, json=None, symbol='USDT_BTC', unit='month', count=6, period=86400):
#     def get_json(self):
#     def set_features(self, partition=1):
#     def set_long_features(self, features, columns_to_set=[], partition=2):
# def set_targets(x, delta=10):
# def eval_features(json):
# def target_code_to_name(code):
# def setup_model(x, y, model_type='random_forest', seed=None, **kwargs):


# Path: docs/example.py
from speculator import market

# Create the random forest model
# The last entry doesn't have a target (can't predict yet), so skip over it
model = market.setup_model(x[:-1], y, model_type='random_forest', seed=1,
                           n_estimators=65, n_jobs=4)

# Predict the target test set from the features test set
trends = model._predict_trends(model.features.test)

# Get accuracies
ftr_imps = model.feature_importances()
conf_mx = model.confusion_matrix(model.targets.test, trends)
acc = model.accuracy(model.features.test, model.targets.test)

# Display accuracies
print('##################')
print('# TEST SET       #')
print('##################')
print('Accuracy: {0:.3f}%'.format(100 * acc))
print('\nConfusion Matrix:')
print(conf_mx)
print(market.TARGET_CODES)
print('\nFeature Importance:')
for ftr, imp in ftr_imps:
    print('  {0}: {1:.3f}%'.format(ftr, 100 * imp))

print()

# Display prediction and probabilities for the next trend
print('##################')
print('# PREDICTED NEXT #')

print('##################')