Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
tianlh
LightGBM-DCU
Commits
f076ca58
Unverified
Commit
f076ca58
authored
May 20, 2021
by
Nikita Titov
Committed by
GitHub
May 20, 2021
Browse files
improve error message for required packages (#4304)
parent
272fedb9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
11 additions
and
8 deletions
+11
-8
examples/python-guide/plot_example.py
examples/python-guide/plot_example.py
+1
-1
python-package/lightgbm/basic.py
python-package/lightgbm/basic.py
+4
-2
python-package/lightgbm/plotting.py
python-package/lightgbm/plotting.py
+4
-4
python-package/lightgbm/sklearn.py
python-package/lightgbm/sklearn.py
+2
-1
No files found.
examples/python-guide/plot_example.py
View file @
f076ca58
...
@@ -6,7 +6,7 @@ import lightgbm as lgb
...
@@ -6,7 +6,7 @@ import lightgbm as lgb
if
lgb
.
compat
.
MATPLOTLIB_INSTALLED
:
if
lgb
.
compat
.
MATPLOTLIB_INSTALLED
:
import
matplotlib.pyplot
as
plt
import
matplotlib.pyplot
as
plt
else
:
else
:
raise
ImportError
(
'You need to install matplotlib for plot_example.py.'
)
raise
ImportError
(
'You need to install matplotlib
and restart your session
for plot_example.py.'
)
print
(
'Loading data...'
)
print
(
'Loading data...'
)
# load or create your dataset
# load or create your dataset
...
...
python-package/lightgbm/basic.py
View file @
f076ca58
...
@@ -2085,7 +2085,8 @@ class Dataset:
...
@@ -2085,7 +2085,8 @@ class Dataset:
elif
isinstance
(
self
.
data
,
pd_DataFrame
):
elif
isinstance
(
self
.
data
,
pd_DataFrame
):
if
not
PANDAS_INSTALLED
:
if
not
PANDAS_INSTALLED
:
raise
LightGBMError
(
"Cannot add features to DataFrame type of raw data "
raise
LightGBMError
(
"Cannot add features to DataFrame type of raw data "
"without pandas installed"
)
"without pandas installed. "
"Install pandas and restart your session."
)
if
isinstance
(
other
.
data
,
np
.
ndarray
):
if
isinstance
(
other
.
data
,
np
.
ndarray
):
self
.
data
=
concat
((
self
.
data
,
pd_DataFrame
(
other
.
data
)),
self
.
data
=
concat
((
self
.
data
,
pd_DataFrame
(
other
.
data
)),
axis
=
1
,
ignore_index
=
True
)
axis
=
1
,
ignore_index
=
True
)
...
@@ -2402,7 +2403,8 @@ class Booster:
...
@@ -2402,7 +2403,8 @@ class Booster:
Returns a pandas DataFrame of the parsed model.
Returns a pandas DataFrame of the parsed model.
"""
"""
if
not
PANDAS_INSTALLED
:
if
not
PANDAS_INSTALLED
:
raise
LightGBMError
(
'This method cannot be run without pandas installed'
)
raise
LightGBMError
(
'This method cannot be run without pandas installed. '
'You must install pandas and restart your session to use this method.'
)
if
self
.
num_trees
()
==
0
:
if
self
.
num_trees
()
==
0
:
raise
LightGBMError
(
'There are no trees in this Booster and thus nothing to parse'
)
raise
LightGBMError
(
'There are no trees in this Booster and thus nothing to parse'
)
...
...
python-package/lightgbm/plotting.py
View file @
f076ca58
...
@@ -80,7 +80,7 @@ def plot_importance(booster, ax=None, height=0.2,
...
@@ -80,7 +80,7 @@ def plot_importance(booster, ax=None, height=0.2,
if
MATPLOTLIB_INSTALLED
:
if
MATPLOTLIB_INSTALLED
:
import
matplotlib.pyplot
as
plt
import
matplotlib.pyplot
as
plt
else
:
else
:
raise
ImportError
(
'You must install matplotlib to plot importance.'
)
raise
ImportError
(
'You must install matplotlib
and restart your session
to plot importance.'
)
if
isinstance
(
booster
,
LGBMModel
):
if
isinstance
(
booster
,
LGBMModel
):
booster
=
booster
.
booster_
booster
=
booster
.
booster_
...
@@ -197,7 +197,7 @@ def plot_split_value_histogram(booster, feature, bins=None, ax=None, width_coef=
...
@@ -197,7 +197,7 @@ def plot_split_value_histogram(booster, feature, bins=None, ax=None, width_coef=
import
matplotlib.pyplot
as
plt
import
matplotlib.pyplot
as
plt
from
matplotlib.ticker
import
MaxNLocator
from
matplotlib.ticker
import
MaxNLocator
else
:
else
:
raise
ImportError
(
'You must install matplotlib to plot split value histogram.'
)
raise
ImportError
(
'You must install matplotlib
and restart your session
to plot split value histogram.'
)
if
isinstance
(
booster
,
LGBMModel
):
if
isinstance
(
booster
,
LGBMModel
):
booster
=
booster
.
booster_
booster
=
booster
.
booster_
...
@@ -294,7 +294,7 @@ def plot_metric(booster, metric=None, dataset_names=None,
...
@@ -294,7 +294,7 @@ def plot_metric(booster, metric=None, dataset_names=None,
if
MATPLOTLIB_INSTALLED
:
if
MATPLOTLIB_INSTALLED
:
import
matplotlib.pyplot
as
plt
import
matplotlib.pyplot
as
plt
else
:
else
:
raise
ImportError
(
'You must install matplotlib to plot metric.'
)
raise
ImportError
(
'You must install matplotlib
and restart your session
to plot metric.'
)
if
isinstance
(
booster
,
LGBMModel
):
if
isinstance
(
booster
,
LGBMModel
):
eval_results
=
deepcopy
(
booster
.
evals_result_
)
eval_results
=
deepcopy
(
booster
.
evals_result_
)
...
@@ -602,7 +602,7 @@ def plot_tree(booster, ax=None, tree_index=0, figsize=None, dpi=None,
...
@@ -602,7 +602,7 @@ def plot_tree(booster, ax=None, tree_index=0, figsize=None, dpi=None,
import
matplotlib.image
as
image
import
matplotlib.image
as
image
import
matplotlib.pyplot
as
plt
import
matplotlib.pyplot
as
plt
else
:
else
:
raise
ImportError
(
'You must install matplotlib to plot tree.'
)
raise
ImportError
(
'You must install matplotlib
and restart your session
to plot tree.'
)
if
ax
is
None
:
if
ax
is
None
:
if
figsize
is
not
None
:
if
figsize
is
not
None
:
...
...
python-package/lightgbm/sklearn.py
View file @
f076ca58
...
@@ -461,7 +461,8 @@ class LGBMModel(_LGBMModelBase):
...
@@ -461,7 +461,8 @@ class LGBMModel(_LGBMModelBase):
and you should group grad and hess in this way as well.
and you should group grad and hess in this way as well.
"""
"""
if
not
SKLEARN_INSTALLED
:
if
not
SKLEARN_INSTALLED
:
raise
LightGBMError
(
'scikit-learn is required for lightgbm.sklearn'
)
raise
LightGBMError
(
'scikit-learn is required for lightgbm.sklearn. '
'You must install scikit-learn and restart your session to use this module.'
)
self
.
boosting_type
=
boosting_type
self
.
boosting_type
=
boosting_type
self
.
objective
=
objective
self
.
objective
=
objective
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment