# Path: discomll/dataset.py
# class Data:
#     def __init__(self, data_tag, X_indices, **kwargs):
#     def generate_urls(self, first_url, last_url):
# 
# Path: discomll/ensemble/distributed_random_forest.py
# def simple_init(interface, params):
# def map_init(interface, params):
# def map_fit(interface, state, label, inp):
# def reduce_fit(interface, state, label, inp):
# def map_predict_voting(interface, state, label, inp):
# def map_predict_dist(interface, state, label, inp):
# def fit(dataset, trees_per_chunk=3, max_tree_nodes=50, min_samples_leaf=10, min_samples_split=5, class_majority=1,
#         measure="info_gain", accuracy=1, separate_max=True, random_state=None, save_results=True, show=False):
# def predict(dataset, fitmodel_url, voting=False, save_results=True, show=False):
# 
# Path: discomll/utils/model_view.py
# def output_model(fitmodel_url):
# def _rf_model(fitmodel):
# def _dt_model(fitmodel):
# def _kmeans_model(fitmodel):
# def _linsvm_model(fitmodel):
# def _logreg_model(fitmodel):
# def _linreg_model(fitmodel):
# def _naivebayes_model(fitmodel):
# def _tree_view(tree, feature_names=[]):
# 
# Path: discomll/utils/accuracy.py
# def simple_init(interface, params):
# def map_predictions(interface, state, label, inp):
# def map_test_data(interface, state, label, inp):
# def reduce_ca(interface, state, label, inp):
# def reduce_mse(interface, state, label, inp):
# def measure(test_data, predictions, measure="ca", save_results=True, show=False):


from disco.core import result_iterator
from discomll import dataset
from discomll.ensemble import distributed_random_forest
from discomll.utils import model_view
from discomll.utils import accuracy


train = dataset.Data(data_tag=[
    ["http://archive.ics.uci.edu/ml/machine-learning-databases/breast-cancer-wisconsin/breast-cancer-wisconsin.data"]],
    id_index=0,
    X_indices=xrange(1, 10),
    X_meta="http://ropot.ijs.si/data/datasets_meta/breastcancer_meta.csv",
    y_index=10,
    delimiter=",")

fit_model = distributed_random_forest.fit(train, trees_per_chunk=3, max_tree_nodes=50, min_samples_leaf=10,
                                          min_samples_split=5, class_majority=1, measure="info_gain", accuracy=1,
                                          separate_max=True, random_state=None, save_results=True)
print model_view.output_model(fit_model)

# predict training dataset
predictions = distributed_random_forest.predict(train, fit_model)

# output results
for k, v in result_iterator(predictions):
    print k, v

# measure accuracy

# Path: discomll/dataset.py
# class Data:
#     def __init__(self, data_tag, X_indices, **kwargs):
#     def generate_urls(self, first_url, last_url):
# 
# Path: discomll/ensemble/distributed_random_forest.py
# def simple_init(interface, params):
# def map_init(interface, params):
# def map_fit(interface, state, label, inp):
# def reduce_fit(interface, state, label, inp):
# def map_predict_voting(interface, state, label, inp):
# def map_predict_dist(interface, state, label, inp):
# def fit(dataset, trees_per_chunk=3, max_tree_nodes=50, min_samples_leaf=10, min_samples_split=5, class_majority=1,
#         measure="info_gain", accuracy=1, separate_max=True, random_state=None, save_results=True, show=False):
# def predict(dataset, fitmodel_url, voting=False, save_results=True, show=False):
# 
# Path: discomll/utils/model_view.py
# def output_model(fitmodel_url):
# def _rf_model(fitmodel):
# def _dt_model(fitmodel):
# def _kmeans_model(fitmodel):
# def _linsvm_model(fitmodel):
# def _logreg_model(fitmodel):
# def _linreg_model(fitmodel):
# def _naivebayes_model(fitmodel):
# def _tree_view(tree, feature_names=[]):
# 
# Path: discomll/utils/accuracy.py
# def simple_init(interface, params):
# def map_predictions(interface, state, label, inp):
# def map_test_data(interface, state, label, inp):
# def reduce_ca(interface, state, label, inp):
# def reduce_mse(interface, state, label, inp):
# def measure(test_data, predictions, measure="ca", save_results=True, show=False):


# Path: discomll/examples/ensemble/drf_breastcancer_url.py
from disco.core import result_iterator
from discomll import dataset
from discomll.ensemble import distributed_random_forest
from discomll.utils import model_view
from discomll.utils import accuracy



train = dataset.Data(data_tag=[
    ["http://archive.ics.uci.edu/ml/machine-learning-databases/breast-cancer-wisconsin/breast-cancer-wisconsin.data"]],
    id_index=0,
    X_indices=xrange(1, 10),
    X_meta="http://ropot.ijs.si/data/datasets_meta/breastcancer_meta.csv",
    y_index=10,
    delimiter=",")

fit_model = distributed_random_forest.fit(train, trees_per_chunk=3, max_tree_nodes=50, min_samples_leaf=10,
                                          min_samples_split=5, class_majority=1, measure="info_gain", accuracy=1,
                                          separate_max=True, random_state=None, save_results=True)
print model_view.output_model(fit_model)

# predict training dataset
predictions = distributed_random_forest.predict(train, fit_model)

# output results
for k, v in result_iterator(predictions):
    print k, v

# measure accuracy

ca = accuracy.measure(train, predictions)