/usr/lib64/python2 7/site-packages/sklearn/utils/validation

在sklearn 0.17版本之后,传递1d数组作为数据被弃用,并将在0.19版本引发ValueError。解决方法是通过reshape函数调整数据形状。如果是单一特征,使用X.reshape(-1, 1);如果是单一样本,则使用X.reshape(1, -1)。例子中提到的是关于匹萨直径和价格的数据训练集。" 135614449,7337247,AI大模型:挑战与解决方案详解,"['人工智能', '语言模型', '深度学习', '数据预处理', '算法复杂性']

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

               

解决:  Passing 1d arrays as data is deprecated in 0.17 and will raise ValueError in 0.19. Reshape your data either using X.reshape(-1, 1) if your data has a single feature or X.reshape(1, -1) if it contains a single sample.

错误信息:
   C:\Python27\lib\site-packages\sklearn\utils\validation.py:395: DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and will raise ValueError in 0.19. Reshape your data either using X.reshape(-1, 1) if your data has a single feature or X.reshape(1, -1) if it contains a single sample.  DeprecationWarning)例子如下:
  

假设匹萨的直径与价格的数据,这就构成了训练数据,如下表所示:

训练样本直径(英寸)价格(美元)
167
289
31013
41417.5
51818
用scikit-learn来构建模型。from sklearn.linear_model import LinearRegression# 创建并拟合模型X = [[6], [8], [10], [14], [18]]y = [[7], [9], [13], [17.5], [18]]model = LinearRegression()model.fit(X, y)print('预测一张12英寸匹萨价格:$%.2f' % model.predict([12])[0])
运行结果如下:
/usr/lib64/python2.7/site-packages/sklearn/utils/validation.py:395: DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and will raise ValueError in 0.19. Reshape your data either using X.reshape(-1, 1) if your data has a single feature or X.reshape(1, -1) if it contains a single sample.  DeprecationWarning)预测一张12英寸匹萨价格:$13.68
我们将最后一句print改成如下:
print('预测一张12英寸匹萨价格:$%.2f' % model.predict(numpy.array([12]).reshape(-1,1))[0])
运行结果就不再上述错误

   

           

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.youkuaiyun.com/jiangjunshow

--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-15-4f9294f36576> in <module> 90 91 if __name__ == "__main__": ---> 92 main() <ipython-input-15-4f9294f36576> in main() 46 # 数据预处理:标准化 47 scaler = StandardScaler() ---> 48 X_scaled = scaler.fit_transform(X_single) 49 50 # 划分训练集和测试集 /usr/local/lib/python3.6/site-packages/sklearn/base.py in fit_transform(self, X, y, **fit_params) 697 if y is None: 698 # fit method of arity 1 (unsupervised transformation) --> 699 return self.fit(X, **fit_params).transform(X) 700 else: 701 # fit method of arity 2 (supervised transformation) /usr/local/lib/python3.6/site-packages/sklearn/preprocessing/_data.py in fit(self, X, y, sample_weight) 728 # Reset internal state before fitting 729 self._reset() --> 730 return self.partial_fit(X, y, sample_weight) 731 732 def partial_fit(self, X, y=None, sample_weight=None): /usr/local/lib/python3.6/site-packages/sklearn/preprocessing/_data.py in partial_fit(self, X, y, sample_weight) 766 X = self._validate_data(X, accept_sparse=('csr', 'csc'), 767 estimator=self, dtype=FLOAT_DTYPES, --> 768 force_all_finite='allow-nan', reset=first_call) 769 n_features = X.shape[1] 770 /usr/local/lib/python3.6/site-packages/sklearn/base.py in _validate_data(self, X, y, reset, validate_separately, **check_params) 419 out = X 420 elif isinstance(y, str) and y == 'no_validation': --> 421 X = check_array(X, **check_params) 422 out = X 423 else: /usr/local/lib/python3.6/site-packages/sklearn/utils/validation.py in inner_f(*args, **kwargs) 61 extra_args = len(args) - len(all_args) 62 if extra_args <= 0: ---> 63 return f(*args, **kwargs) 64 65 # extra_args > 0 /usr/local/lib/python3.6/site-packages/sklearn/utils/validation.py in check_array(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, estimator) 671 array = array.astype(dtype, casting="unsafe", copy=False) 672 else: --> 673 array = np.asarray(array, order=order, dtype=dtype) 674 except ComplexWarning as complex_warning: 675 raise ValueError("Complex data not supported\n" /usr/local/lib/python3.6/site-packages/numpy/core/_asarray.py in asarray(a, dtype, order) 81 82 """ ---> 83 return array(a, dtype, copy=False, order=order) 84 85 ValueError: could not convert string to float: 'area'
06-11
(rasa) unitree@ubuntu:~/rasa_ws$ rasa run --enable-api /home/unitree/rasa/lib/python3.8/site-packages/rasa/core/tracker_store.py:1044: MovedIn20Warning: Deprecated API features detected! These feature(s) are not compatible with SQLAlchemy 2.0. To prevent incompatible upgrades prior to updating applications, ensure requirements files are pinned to "sqlalchemy<2.0". Set environment variable SQLALCHEMY_WARN_20=1 to show all deprecation warnings. Set environment variable SQLALCHEMY_SILENCE_UBER_WARNING=1 to silence this message. (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9) Base: DeclarativeMeta = declarative_base() /home/unitree/rasa/lib/python3.8/site-packages/rasa/shared/utils/validation.py:134: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html import pkg_resources /home/unitree/rasa/lib/python3.8/site-packages/pkg_resources/__init__.py:3117: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('mpl_toolkits')`. Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages declare_namespace(pkg) /home/unitree/rasa/lib/python3.8/site-packages/pkg_resources/__init__.py:3117: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('ruamel')`. Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages declare_namespace(pkg) /home/unitree/rasa/lib/python3.8/site-packages/sanic_cors/extension.py:39: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead. SANIC_VERSION = LooseVersion(sanic_version) Traceback (most recent call last): File "/home/unitree/rasa/lib/python3.8/site-packages/sklearn/__check_build/__init__.py", line 48, in <module> from ._check_build import check_build # noqa ImportError: /home/unitree/rasa/lib/python3.8/site-packages/sklearn/__check_build/../../scikit_learn.libs/libgomp-d22c30c5.so.1.0.0: cannot allocate memory in static TLS block During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/unitree/rasa/bin/rasa", line 8, in <module> sys.exit(main()) File "/home/unitree/rasa/lib/python3.8/site-packages/rasa/__main__.py", line 133, in main cmdline_arguments.func(cmdline_arguments) File "/home/unitree/rasa/lib/python3.8/site-packages/rasa/cli/run.py", line 93, in run rasa.run(**vars(args)) File "/home/unitree/rasa/lib/python3.8/site-packages/rasa/api.py", line 36, in run import rasa.core.run File "/home/unitree/rasa/lib/python3.8/site-packages/rasa/core/run.py", line 25, in <module> from rasa import server, telemetry File "/home/unitree/rasa/lib/python3.8/site-packages/rasa/server.py", line 59, in <module> from rasa.core.agent import Agent File "/home/unitree/rasa/lib/python3.8/site-packages/rasa/core/agent.py", line 22, in <module> from rasa.core.policies.policy import PolicyPrediction File "/home/unitree/rasa/lib/python3.8/site-packages/rasa/core/policies/policy.py", line 26, in <module> from rasa.core.featurizers.tracker_featurizers import TrackerFeaturizer File "/home/unitree/rasa/lib/python3.8/site-packages/rasa/core/featurizers/tracker_featurizers.py", line 31, in <module> from rasa.core.featurizers.single_state_featurizer import SingleStateFeaturizer File "/home/unitree/rasa/lib/python3.8/site-packages/rasa/core/featurizers/single_state_featurizer.py", line 8, in <module> from rasa.nlu.extractors.extractor import EntityTagSpec File "/home/unitree/rasa/lib/python3.8/site-packages/rasa/nlu/extractors/extractor.py", line 30, in <module> import rasa.utils.train_utils File "/home/unitree/rasa/lib/python3.8/site-packages/rasa/utils/train_utils.py", line 32, in <module> from rasa.utils.tensorflow.data_generator import RasaBatchDataGenerator File "/home/unitree/rasa/lib/python3.8/site-packages/rasa/utils/tensorflow/data_generator.py", line 10, in <module> from rasa.utils.tensorflow.model_data import RasaModelData, Data, FeatureArray File "/home/unitree/rasa/lib/python3.8/site-packages/rasa/utils/tensorflow/model_data.py", line 21, in <module> from sklearn.model_selection import train_test_split File "/home/unitree/rasa/lib/python3.8/site-packages/sklearn/__init__.py", line 81, in <module> from . import __check_build # noqa: F401 File "/home/unitree/rasa/lib/python3.8/site-packages/sklearn/__check_build/__init__.py", line 50, in <module> raise_build_error(e) File "/home/unitree/rasa/lib/python3.8/site-packages/sklearn/__check_build/__init__.py", line 31, in raise_build_error raise ImportError( ImportError: /home/unitree/rasa/lib/python3.8/site-packages/sklearn/__check_build/../../scikit_learn.libs/libgomp-d22c30c5.so.1.0.0: cannot allocate memory in static TLS block ___________________________________________________________________________ Contents of /home/unitree/rasa/lib/python3.8/site-packages/sklearn/__check_build: __pycache__ setup.py __init__.py _check_build.cpython-38-aarch64-linux-gnu.so ___________________________________________________________________________ It seems that scikit-learn has not been built correctly. If you have installed scikit-learn from source, please do not forget to build the package before using it: run `python setup.py install` or `make` in the source directory. If you have used an installer, please check that it is suited for your Python version, your operating system and your platform. 这是我出现的错误
最新发布
07-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值