python - 如何从 GaussianProcessClassifier 中提取估计参数 (theta)

标签 python scikit-learn classification gaussian

# Scale/ Normalize Independent Variables 
X = StandardScaler().fit_transform(X) 
#Split data into train an test set at 50% each
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=.5, random_state=42) 
gpc= GaussianProcessClassifier(1.0 * RBF(1.0), n_jobs=-1)
gpc.fit(X_train,y_train)
y_proba=gpc.predict_proba(X_test)
#classify as 1 if prediction probablity greater than 15.8%
y_pred = [1 if x >= .158 else 0 for x in y_proba[:, 1]]

上面的代码按预期运行。然而,为了解释该模型,比如“Beta1 中 1 个单位的变化将导致成功概率提高 0.7%”,我需要能够看到 theta。我该怎么做呢? 感谢您的协助。顺便说一句,这是一项家庭作业

最佳答案

非常好的问题。您确实可以访问thetas,但是在文档中并不清楚如何执行此操作。


使用以下内容。这里我使用 iris 数据集。

from sklearn.gaussian_process.kernels import RBF
from sklearn.gaussian_process import GaussianProcessClassifier
from sklearn.preprocessing import StandardScaler
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split

# Scale/ Normalize Independent Variables 
X = StandardScaler().fit_transform(X) 

#Split data into train an test set at 50% each
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size= .5, random_state=42) 

gpc= GaussianProcessClassifier(1.0 * RBF(1.0), n_jobs=-1)
gpc.fit(X_train,y_train)
y_proba=gpc.predict_proba(X_test)

#classify as 1 if prediction probablity greater than 15.8%
y_pred = [1 if x >= .158 else 0 for x in y_proba[:, 1]]

# thetas
gpc.kernel_.theta

结果:

array([7.1292252 , 1.35355145, 5.54106817, 0.61431805, 7.00063873,
       1.3175175 ])

可以在 HERE 找到访问 thetas 的文档示例。


希望这有帮助。

关于python - 如何从 GaussianProcessClassifier 中提取估计参数 (theta),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50668340/

相关文章:

python - 尝试显示小部件时出现线程问题

scikit-learn - sklearn.preprocessing 中没有 StandardScaler 类

python - 如何对缩放回归模型执行约束优化?

python - 如何对未标记的数据进行分类?

python - 使用 Keras 对 3 类进行图像分类仅返回一个值,而不是 1 X 3 数组

python - 大数据训练分类器

python - 加入两个numpy矩阵

javascript - 在 Django 中,如何在管理表单中显示站点缩写而不是完整的站点域?

python - 使用 django-hosts 的多个子域的一个 View

machine-learning - Python(scikit learn)lda 崩溃为单一维度