Esempio n. 1
0
import xgboost as xgb
import testing as tm

import unittest
import pytest

try:
    import matplotlib
    matplotlib.use('Agg')
    from matplotlib.axes import Axes
    from graphviz import Source
except ImportError:
    pass

pytestmark = pytest.mark.skipif(
    **tm.no_multiple(tm.no_matplotlib(), tm.no_graphviz()))

dpath = 'demo/data/agaricus.txt.train'


class TestPlotting(unittest.TestCase):
    def test_plotting(self):
        m = xgb.DMatrix(dpath)
        booster = xgb.train(
            {
                'max_depth': 2,
                'eta': 1,
                'objective': 'binary:logistic'
            },
            m,
            num_boost_round=2)
Esempio n. 2
0
# -*- coding: utf-8 -*-
import numpy as np
import xgboost as xgb
import testing as tm

import pytest

try:
    import matplotlib
    matplotlib.use('Agg')
    from matplotlib.axes import Axes
    from graphviz import Source
except ImportError:
    pass

pytestmark = pytest.mark.skipif(**tm.no_multiple(tm.no_matplotlib(),
                                                 tm.no_graphviz()))

dpath = 'demo/data/agaricus.txt.train'


class TestPlotting:
    def test_plotting(self):
        m = xgb.DMatrix(dpath)
        booster = xgb.train({'max_depth': 2, 'eta': 1,
                             'objective': 'binary:logistic'}, m,
                            num_boost_round=2)

        ax = xgb.plot_importance(booster)
        assert isinstance(ax, Axes)
        assert ax.get_title() == 'Feature importance'
        assert ax.get_xlabel() == 'F score'