- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我对 python 很陌生,对做高斯回归很感兴趣。我在 py3.6 和 SKlearn 0.19 下。
我有简单的代码,但我得到了一个关于预测调用的 cdist 中向量维度的错误。我知道我的输入有问题。但我不明白为什么...
我找了高斯过程回归器的例子,但它似乎不是最常用的工具。
预先感谢您的帮助。
干杯。
这是我的代码示例:
import pandas as pd
import numpy as np
import numpy as np
from sklearn.gaussian_process import GaussianProcessRegressor as gpr
from sklearn.gaussian_process.kernels import RBF, ConstantKernel as C
....
#X_train are the training samples
X_train= np.column_stack((xc,yc,zc))
print('X_train')
print(X_train.shape)
print(X_train)
这是 X_train 的输出:
X_train (4576, 3)
[[ 0.71958336 -1.12719598 0.47889958]
[ 0.71958336 -1.12719598 0.47889958]
[ 0.71958336 -1.12719598 0.34285071]
...
[ 0.55255508 -1.18817547 -1.63666023]
[ 0.55255508 -1.18817547 -1.70468466]
[ 0.55255508 -1.18817547 -1.77270909]]
这是训练的目标特征:
print('v1')
print(v1.shape)
print(v1)
它的打印
v1
(4576,)
0 10.0
1 14.0
2 13.0
3 19.0
....
4573 39.0
4574 16.0
4575 12.0
这里是要预测的样本:
x = np.column_stack((xp,
yp,
zp))
print('x')
print(x.shape)
print(x)
这是打印品:
x
(75, 3)
[[-1.41421356 -1.41421356 -1.22474487]
[-0.70710678 -1.41421356 -1.22474487]
[ 0. -1.41421356 -1.22474487]
[ 0.70710678 -1.41421356 -1.22474487]
.....
[ 0.70710678 -0.70710678 -1.22474487]
[ 1.41421356 -0.70710678 -1.22474487]
[-1.41421356 0. -1.22474487]
[-0.70710678 0. -1.22474487]
[ 0. 0. -1.22474487]
这里是拟合和预测
v1 = v1.ravel()
#default kernel
kernel = C(1.0, (1e-3, 1e3)) * RBF(10, (1e-2, 1e2))
X_train, v1 = make_regression()
model = gpr(kernel=kernel, n_restarts_optimizer=9)
model.fit(X_train,v1)
#Predict v1
v1_pred = model.predict(x)
运行时出现如下错误:
File "test.py", line 189, in test v1_pred = model.predict(x) File "/usr/local/lib/python3.6/site-packages/sklearn/gaussian_process/gpr.py", line 315, in predict K_trans = self.kernel_(X, self.X_train_) File "/usr/local/lib/python3.6/site-packages/sklearn/gaussian_process/kernels.py", line 758, in call return self.k1(X, Y) * self.k2(X, Y) File "/usr/local/lib/python3.6/site-packages/sklearn/gaussian_process/kernels.py", line 1215, in call metric='sqeuclidean') File "/usr/local/lib/python3.6/site-packages/scipy/spatial/distance.py", line 2373, in cdist raise ValueError('XA and XB must have the same number of columns ' ValueError: XA and XB must have the same number of columns (i.e. feature dimension.)
最佳答案
我只是简单地复制粘贴了一段代码,然后做了一些愚蠢的事情:
X_train, v1 = make_regression()
只好删除它。
关于python - Sklearn,高斯过程 : XA and XB must have the same number of columns,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49068574/
我知道有几个类似的问题被问到,但我的问题仍然没有得到解答。 问题来了。我使用命令 python3 -m pip3 install -U scikit-learn 来安装 sklearn、numpy 和
_train_weather.values : [[ 0.61818182 0.81645199 0.6679803 ..., 0. 0. 1.
如果我有一个数据集X及其标签Y,那么我将其分为训练集和测试集,scle为0.2,并使用随机种子进行洗牌: 11 >>>X.shape (10000, 50,50) train_data, test_d
首先我查看了所有相关问题。给出了非常相似的问题。 所以我遵循了链接中的建议,但没有一个对我有用。 Data Conversion Error while applying a function to
这里有两种标准化方法: 1:这个在数据预处理中使用:sklearn.preprocessing.normalize(X,norm='l2') 2:分类方法中使用另一种方法:sklearn.svm.Li
所以刚看了一个教程,作者不需要import sklearn使用时 predict anaconda 环境中pickled 模型的功能(安装了sklearn)。 我试图在 Google Colab 中重
我想评估我的机器学习模型。我使用 roc_auc_score() 计算了 ROC 曲线下的面积,并使用 sklearn 的 plot_roc_curve() 函数绘制了 ROC 曲线。在第二个函数中,
我一直在寻找此信息,但在任何地方都找不到,所以这是我的镜头。 我是Python 2.7的初学者,我学习了一个模型,感谢cPickle我保存了它,但现在我想知道是否可以从另一个设备(没有sklearn库
>>> import sklearn.model_selection.train_test_split Traceback (most recent call last): File "", li
在阅读有关使用 python 的 LinearDiscriminantAnalysis 的过程中,我有两种不同的方法来实现它,可在此处获得, http://scikit-learn.org/stabl
我正在使用 sklearn,我注意到 sklearn.metrics.plot_confusion_matrix 的参数和 sklearn.metrics.confusion_matrix不一致。 p
我正在构建一个多标签文本分类程序,我正在尝试使用 OneVsRestClassifier+XGBClassifier 对文本进行分类。最初,我使用 Sklearn 的 Tf-Idf 矢量化来矢量化文本
我想看看模型是否收敛于我的交叉验证。我如何增加或减少 sklearn.svm.SVC 中的时代? 目前: SVM_Model = SVC(gamma='auto') SVM_Model.fit(X_t
有人可以帮助我吗?我很难知道它们之间的区别 from sklearn.model_selection import train_test_split from sklearn.cross_valida
我需要提取在 sklearn.ensemble.BaggingClassifier 中训练的每个模型的概率。这样做的原因是为了估计 XGBoostClassifier 模型的不确定性。 为此,我创建了
无法使用 scikit-learn 0.19.1 导入 sklearn.qda 和 sklearn.lda 我得到: 导入错误:没有名为“sklearn.qda”的模块 导入错误:没有名为“sklea
我正在尝试在 google cloud ai 平台上创建一个版本,但找不到 impute 模块 No module named 'sklearn.impute._base; 'sklearn.impu
我在 PyQt5 中编写了一个 GUI,其中包括以下行 from sklearn.ensemble import RandomForestClassifier 。 遵循this answer中的建议,
我正在做一个 Kaggle 比赛,需要输入一些缺失的数据。我安装了最新的Anaconda(4.5.4)具有所有相关依赖项(即 scikit-learn (0.19.1) )。 当我尝试导入模块时,出现
在安装了所需的模块后,我正在尝试将imblearn导入到我的Python笔记本中。但是,我收到以下错误:。。附加信息:我使用的是一个用Visual Studio代码编写的虚拟环境。。我已经确定venv
我是一名优秀的程序员,十分优秀!