Issue
If I calculate the validation curve like follows:
PolynomialRegression(degree=2,**kwargs):
return make_pipeline(PolynomialFeatures(degree),LinearRegression(**kwargs))
#...
degree=np.arange(0,21)
train_score,val_score=validation_curve(PolynomialRegression(),X,y,"polynomialfeatures__degree",degree,cv=7)
the function claims the parameter "param_name" which is the name of the parameter that will be evaluated ("param_range") In this case it is polynomialfeatures__degree. But:
- From where do I get the string for "param_name" in general and from where do I get the string "polynomialfeatures__degree" in particular because I can't find this param_name in any documentation...Is the "function__param name" a common way to point on the param_name of a function??
- For which estimators can I use the validation_curve function?
Solution
PART 1
Answer to your question # 1:
As param_name
you can use one of the available parameters of the estimator of your choice.
For example: Let's say that you choose the estimator: LinearRegression
. From this link you can see than the available parameters/arguments are fit_intercept=True, normalize=False, copy_X=True, n_jobs=1
. So now you know what are the available parameters of the specific estimator.
Now, from this link we can see how to define the param_name
and param_range
.
Part of the example in this link:
param_range = np.logspace(-6, -1, 5)
train_scores, test_scores = validation_curve(
SVC(), X, y, param_name="gamma", param_range=param_range,
cv=10, scoring="accuracy", n_jobs=1)
EDIT 1:
For the "string" as you call it: if I understand right you want to do something like:
from sklearn.preprocessing import PolynomialFeatures
a= PolynomialFeatures(degree=2)
a.get_params()
result:
{'include_bias': True, 'interaction_only': False, 'degree': 2}
These are the available param_names for the PolynomialFeatures.
EDIT 2:
Another way to see the param_names
is to go to the source code.
For example, here link you can see in lines 1149-1160 the strings of the parameters for the PolynomialFeatures
estimator.
Finally, here link you can see in lines 421-444 the strings of the parameters for the LinearRegression
estimator.
EDIT 3:
Other way to get and set the parameters of estimator in sklearn.
from sklearn.linear_model import LinearRegression
lr = LinearRegression()
lr.get_params(deep=True)
result:
{'copy_X': True, 'normalize': False, 'n_jobs': 1, 'fit_intercept': True}
Now that you know the parameters you create your parameters:
params = { 'copy_X': False, 'fit_intercept': True, 'normalize': True }
And then you can unpack them in the estimator:
lr_new = LinearRegression(**params)
lr_new
result:
LinearRegression(copy_X=True, fit_intercept=False, n_jobs=1, normalize=True)
PART 2:
Answer to your question # 2:
I think that in the case of sklearn
module, you can use the validation_curve
for all the estimators.
Hope this helps
Answered By - seralouk
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.