我想从""
模型中获得逻辑回归的边际效应
我知道您可以使用'.get_margeff()'将其用于statsmodel logistic回归。 sklearn没有东西吗?我想避免自己做计算,因为我认为错误的余地很大。
iAmLoaded = True
Dim i = 0
For Each LabelOnTheForm As Label In TabControl1.TabPages(i).Controls
'The problem is at the second iteration of the for loop, it has a button instead of a label
'How do I design a "If" statement to test if the control I am working with is a label and not a button
If LabelOnTheForm = Label Then '<--- produces error 'Label' is a class type and cannot be used as an expression
If DirectCast(LabelOnTheForm, Label).Text <> "" And DirectCast(LabelOnTheForm, Label).Text <> "0" Then
DirectCast(LabelOnTheForm, Label).Text = (Convert.ToDouble(DirectCast(LabelOnTheForm, Label).Text) + 1).ToString
DirectCast(LabelOnTheForm, Label).Text = (Convert.ToDouble(DirectCast(LabelOnTheForm, Label).Text) - 1).ToString
i = i + 1
Else
i = i + 1
End If
End If
Next
End Sub
自定义函数的功能与“ sklearn
”相同,但是在上述自定义函数中使用sklearn ceof_时可能会有很多错误的余地。
答案 0 :(得分:0)
几天前我刚达到这个要求。
我的主管给了我我想分享的信息。希望对您有所帮助。
partial_dependence:此方法可以获取您想要的partial dependence
或marginal effects
。
plot_partial_dependence:此方法可以绘制partial dependence
。
这是API参考中的示例代码。
scikit-learn version: 0.21.2
from sklearn.inspection import plot_partial_dependence, partial_dependence
from sklearn.datasets import make_friedman1
from sklearn.linear_model import LinearRegression
from sklearn.ensemble import GradientBoostingRegressor
%matplotlib inline
X, y = make_friedman1()
# case1: linear model
lm = LinearRegression().fit(X, y)
# plot the partial dependence
plot_partial_dependence(lm, X, [0, (0, 1)])
# get the partial dependence
partial_dependence(lm, X, [0])
# case2: classifier
clf = GradientBoostingRegressor(n_estimators=10).fit(X, y)
# plot the partial dependence
plot_partial_dependence(clf, X, [0, (0, 1)])
# get the partial dependence
partial_dependence(clf, X, [0])