【问题标题】:How do I extract the estimation parameters (theta) from GaussianProcessClassifier如何从 GaussianProcessClassifier 中提取估计参数(theta)
【发布时间】:2018-11-13 01:35:42
【问题描述】:
# 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。我该怎么做呢? 感谢您的协助。顺便说一句,这是家庭作业

【问题讨论】:

  • 查看我的答案并告诉我

标签: python scikit-learn classification gaussian


【解决方案1】:

非常好的问题。您确实可以访问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的文档示例


希望这会有所帮助。

【讨论】:

    【解决方案2】:

    看起来您正在寻找的theta 值是您传递给分类器的内核对象的一个​​属性。你可以阅读更多in this section of the sklearn documentation。您可以使用classifier.kernel_.theta 访问分类器内核的theta 的对数转换值,其中classifier 是您的分类器对象的名称。

    请注意,kernel object 也有一个方法 clone_with_theta(theta),如果您对 theta 进行修改,它可能会派上用场。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-26
      • 1970-01-01
      • 1970-01-01
      • 2021-03-11
      • 2018-10-27
      • 1970-01-01
      相关资源
      最近更新 更多