如何从高斯过程分类中提取估计参数(θ)

2024-06-11 04:43:37 发布

您现在位置:Python中文网/ 问答频道 /正文

# 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%的提高”,我需要能够看到θ。我该怎么做? 谢谢你的帮助。顺便说一句,这是家庭作业


Tags: testdataiftransformtrainvariablesfitsplit
2条回答

很好的问题。您确实可以访问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 ])

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


希望这有帮助。你知道吗

看起来您要查找的theta值似乎是传递给分类器的内核对象的属性。你可以阅读更多的in this section of the sklearn documentation。您可以使用classifier.kernel_.theta访问分类器内核的θ的日志转换值,其中classifier是分类器对象的名称。你知道吗

注意,kernel object还有一个方法clone_with_theta(theta),如果您要修改θ,这个方法可能会派上用场。你知道吗

相关问题 更多 >