I'm getting the following error while importing LGBMResgressor to lightgbm:
ImportError
Traceback (most recent call last)
<ipython-input-38-1a53b4f7b770> in <module>()
5 from sklearn.kernel_ridge import KernelRidge
6 import lightgbm as lgb
----> 7 from lightgbm import LGBMRegressor
8 # from lightgbm.sklearn import LGBMRegressor
9 from sklearn.base import BaseEstimator, TransformerMixin, RegressorMixin, clone
ImportError: cannot import name 'LGBMRegressor'
lightgbm's version is 2.0.5, and it is installed on Windows 10 by pip install lightgbm.
My environment is linux (python 3.6.1) and I installed with pip install lightgbm, opened a ipython terminal and copy your imports and not occurred error, but i can see an 'inconsistence' in your imports. On line six you make:
import lightgbm as lgb
And on the next line
from lightgbm import LGBMRegressor
On line 6 you already import all module as lgb (line 7 is unnecessary), for use LGBMRegressor just do:
lgb.LGBMRegressor
Finnaly, to make sure that the module are insalled, type in a command line:
python -c "import lightgbm; print(lightgbm.__version__)"
Output:
2.0.1
Related
I am working on a jupyter notebook project which should use spacy. I already used pip install to install spacy in anaconda prompt.
However, when I tried to import spacy, it gives me the follwing error.
I wonder what the problem is and what I can do to solve that.
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-96-3173a3034708> in <module>
9 #nltk.download()
10 from nltk.corpus import stopwords
---> 11 import spacy
12
13 #path where we store the txt files
D:\Python\lib\site-packages\spacy\__init__.py in <module>
4
5 # set library-specific custom warning handling before doing anything else
----> 6 from .errors import setup_default_warnings
7
8 setup_default_warnings() # noqa: E402
D:\Python\lib\site-packages\spacy\errors.py in <module>
1 import warnings
----> 2 from .compat import Literal
3
4
5 class ErrorsWithCodes(type):
D:\Python\lib\site-packages\spacy\compat.py in <module>
1 """Helpers for Python and platform compatibility."""
2 import sys
----> 3 from thinc.util import copy_array
4
5 try:
D:\Python\lib\site-packages\thinc\util.py in <module>
6 import functools
7 from wasabi import table
----> 8 from pydantic import create_model, ValidationError
9 import inspect
10 import os
D:\Python\lib\site-packages\pydantic\__init__.cp38-win_amd64.pyd in init pydantic.__init__()
D:\Python\lib\site-packages\pydantic\dataclasses.cp38-win_amd64.pyd in init pydantic.dataclasses()
ImportError: cannot import name dataclass_transform
You can try following codes:
pip install -U pip setuptools wheel
pip install -U spacy
python -m spacy download en_core_web_sm
After installation restart the kernal if you are using Jupyter notebook or lab.
It does works for my end.
I am using Windows with Anaconda virtual environment. Uninstalling spacy from pip and installing it from conda did the job for me.
pip uninstall spacy
conda install spacy
python -m spacy download en_core_web_sm --user
I don't know why I am getting this error, the official document reference
https://scikit-learn.org/stable/modules/generated/sklearn.metrics.det_curve.html#sklearn.metrics.det_curve
Code:
import numpy as np
from sklearn.metrics import det_curve
fpr, fnr, thresholds = det_curve(y_test, y_pred)
print(fpr, fnr, thresholds)
Error:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-46-d8d6f0b546ca> in <module>()
10
11 import numpy as np
---> 12 from sklearn.metrics import det_curve
13
14 fpr, fnr, thresholds = det_curve(y_test['cEXT'], y_pred)
ImportError: cannot import name 'det_curve' from 'sklearn.metrics' (/usr/local/lib/python3.7/dist-packages/sklearn/metrics/__init__.py)
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------
Same kind of problem happened to me in my Jupyter notebook. I uninstall and re-install both scikit-learn and imblearn. It didn't work. Then restarting the kernel and running again solved the problem.
Looks like some issue with a missing package. Try the following:
pip uninstall -v scikit-learn
pip install -v scikit-learn
This might install the related dependencies along with it.
I am trying to run this tutorial in colab.
However, when I try to import a bunch of modules:
import io
import torch
from torchtext.utils import download_from_url
from torchtext.data.utils import get_tokenizer
from torchtext.vocab import build_vocab_from_iterator
It gives me the errors for extract_archive and build_vocab_from_iterator:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-5-a24e72502dbc> in <module>()
1 import io
2 import torch
----> 3 from torchtext.utils import download_from_url, extract_archive
4 from torchtext.data.utils import get_tokenizer
5 from torchtext.vocab import build_vocab_from_iterator
ImportError: cannot import name 'extract_archive'
ImportError Traceback (most recent call last)
<ipython-input-4-02a401fd241b> in <module>()
3 from torchtext.utils import download_from_url
4 from torchtext.data.utils import get_tokenizer
----> 5 from torchtext.vocab import build_vocab_from_iterator
6
7 url = 'https://s3.amazonaws.com/research.metamind.io/wikitext/wikitext-2-v1.zip'
ImportError: cannot import name 'build_vocab_from_iterator'
Please help me with this one.
You need to upgrade torchtext first
!pip install -U torchtext==0.8.0
Currently, version 0.8.0 works with torch 1.7.0 (no need to upgrade torch, torchvision)
Update (sep 2021)
Currently, torchtext is already 0.10.0 and you don't need to upgrade anything.
Update December 2021
!pip install -U torchtext==0.10.0
torchtext.data becomes torchtext.legacy.data
use:
from torchtext.legacy.data import Field, TabularDataset, BucketIterator, Iterator
credit
You can use:
pip install -U torchtext==0.6.0
if 0.8 version is not available
This might help solve your problem:
conda install -c pytorch torchtext==0.8
I'm trying to import xgboost into jupyter-notebook but get the following error:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-9-a585b270d0df> in <module>
1 import pandas as pd
2 import numpy as np
----> 3 import xgboost
~/.local/lib/python3.6/site-packages/xgboost/__init__.py in <module>
14 from . import tracker # noqa
15 from .tracker import RabitTracker # noqa
---> 16 from . import dask
17 try:
18 from .sklearn import XGBModel, XGBClassifier, XGBRegressor, XGBRanker
~/.local/lib/python3.6/site-packages/xgboost/dask.py in <module>
31 from .training import train as worker_train
32 from .tracker import RabitTracker
---> 33 from .sklearn import XGBModel, XGBClassifierBase, xgboost_model_doc
34
35 # Current status is considered as initial support, many features are
ModuleNotFoundError: No module named 'xgboost.sklearn'
I've downloaded sklearn as well as sci-kit learn and they work fine...
Any idea what the problem is?
You might need to install your packages properly.
For best practice, you'll need to use a conda environment. Check out how it works here: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html
Once you have created your environment, activate it and then install all the packages you need. Presumably, you'll have to run the command:
conda install -c conda-forge xgboost
pip install -U scikit-learn
To install your machine learning packages.
XGBOOST is in xgboost module: It should be imported as:
`from xgboost import XGBRegressor`
I am trying to install and utilize pymer4 package functionalities in Databricks which requires rpy2 to be installed as well. Under Library in the Cluster I am able to install them, it even says "Installed", but when I try to import them then it gives error, as if it was not installed properly. In local system it works perfectly.
from pymer4.test_install import test_install
Error is:
ImportError: No module named 'pandas.core.dtypes'
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<command-2946392196605768> in <module>()
----> 1 from pymer4.test_install import test_install
/databricks/python/lib/python3.5/site-packages/pymer4/__init__.py in <module>()
6 "__version__"]
7
----> 8 from .models import Lmer, Lm
9 from .simulate import (easy_multivariate_normal,
10 simulate_lm,
/databricks/python/lib/python3.5/site-packages/pymer4/models.py in <module>()
2 import rpy2.robjects as robjects
3 from rpy2.robjects.packages import importr
----> 4 from rpy2.robjects import pandas2ri
5 import rpy2
6 from copy import copy
/databricks/python/lib/python3.5/site-packages/rpy2/robjects/pandas2ri.py in <module>()
14 from pandas.core.series import Series as PandasSeries
15 from pandas.core.index import Index as PandasIndex
---> 16 from pandas.core.dtypes.api import is_datetime64_any_dtype
17 import pandas
18 import numpy
ImportError: No module named 'pandas.core.dtypes'
Was able to solve my own problem. It was nothing but version issues of dependent packages of pymer4 package.
Changed the version of following packages with the latest one prior to release date of pymer4 and it worked:
matplotlib==3.0.2
pandas==0.23.4
rpy2==2.9.4
tzlocal