def serialize_tree(tree, feature_names, outfile):
        """
        :type feature_names: list
        :type tree: sklearn.tree.tree.BaseDecisionTree
        :param tree: sklearn.tree.tree
        :param feature_names:
        :return:
        """

        tree_ = tree.tree_
        feature_name = [feature_names[i] if i != _tree.TREE_UNDEFINED else 'n/a' for i in tree_.feature]

        def traverse(node, depth, outfile):
            if tree_.feature[node] != _tree.TREE_UNDEFINED:
                name = feature_name[node]
                threshold = tree_.threshold[node]

                # Define internal node for serialization
                internal_node = {
                    'type': 'internal',
                    'split': {
                        'type': 'continuous',
                        'featureIndex': feature_names.index(name),
                        'threshold': threshold
                    }
                }

                # Serialize the internal Node
                json.dump(internal_node, outfile)
                outfile.write('\n')

                # Traverse Left
                traverse(tree_.children_left[node], depth + 1, outfile)

                # Traverse Rigiht
                traverse(tree_.children_right[node], depth + 1, outfile)
            else:
                leaf_node = {
                    'type': 'leaf',
                    'values': tree_.value[node].tolist()[0]
                }

                # Serialize the leaf node
                json.dump(leaf_node, outfile)
                outfile.write('\n')

        traverse(0, 1, outfile)
:type feature_names: list
        :type tree: sklearn.tree.tree.BaseDecisionTree
        :param tree: sklearn.tree.tree
        :param feature_names:
        :return: