Hi Emeline.
You can use the GridSearchCV to find the gamma parameter for a precomputed kernel, but it is somewhat
non-trivial.
The solution I would suggest is to use IterGrid <http://scikit-learn.org/dev/modules/generated/sklearn.grid_search.IterGrid.html#sklearn.grid_search.IterGrid> instead.
This way you could do something like:

for train, test in cross_validation():
    for gamma, C in IterGrid(params):
        kernel = precompute_kernel(X[train], gamma)
        svc.set_param(C=C)
        svc.fit(kernel, y[train])
        kernel_test = precompute_kernel_test(X[train], X[test], gamma)
        scores.append(svc.score(kernel_test, y[test]))

The other possibility to use GridSearchCV directly would be to create an estimator that precomputes the kernel, generate a pipeline from this estimator and the svm and
then use GridSearchCV on the Pipeline.
That shouldn't be to hard either, but requires some knowledge of sklearn.

Cheers,
Andy


Am 23.05.2012 15:08, schrieb Emeline Landemaine:
Ok! Last question: I saw that the grid search works to find the appropriate C parameter. Is it possible to make it work also to find the optimal gamma parameter of my precomputed RBF kernel?

Regards,
Emeline

2012/5/23 Andreas Mueller <[email protected] <mailto:[email protected]>>

    Sorry about being unclear.
    It is not possible to use another distance in the RBF kernel. You
    have to precompute it your own.
    But it is possible to do grid search using the precomputed kernel.

    Cheers,
    Andy


    Am 23.05.2012 14:58, schrieb Emeline Landemaine:
    I'm not sure to understand: do you mean that this is possible to
    change the distance used within the RBF kernel because I didn't
    see documentation about it?

    Thank you

    2012/5/23 Andreas Mueller <[email protected]
    <mailto:[email protected]>>

        Hi Emeline.

        >
        > I would like to use SVM in scikit-learn with a RBF kernel
        K(x,y)= exp(
        > -gamma *d(x,y)^2 ) with d that is not the usual distance but a
        > weighted sum of other distances.
        > How can I do so? Do I have to precompute the kernel on my own?
        Yes, you have to precompute the whole kernel.
        > Moreover, to determine gamma, I would like to perform
        cross-validation
        > on a grid-search but I'm not sure if it's possible with a
        precomputed
        > kernel ...
        >
        This is supported at least since 0.11, maybe earlier.
        The code is not very mature yet so if you run into any
        troubles, please
        let us know.

        Cheers,
        Andy


        
------------------------------------------------------------------------------
        Live Security Virtual Conference
        Exclusive live event will cover all the ways today's security and
        threat landscape has changed and how IT managers can respond.
        Discussions
        will include endpoint security, mobile security and the
        latest in malware
        threats.
        http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
        _______________________________________________
        Scikit-learn-general mailing list
        [email protected]
        <mailto:[email protected]>
        https://lists.sourceforge.net/lists/listinfo/scikit-learn-general



    
------------------------------------------------------------------------------
    Live Security Virtual Conference
    Exclusive live event will cover all the ways today's security and
    threat landscape has changed and how IT managers can respond. Discussions
    will include endpoint security, mobile security and the latest in malware
    threats.http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/


    _______________________________________________
    Scikit-learn-general mailing list
    [email protected]  
<mailto:[email protected]>
    https://lists.sourceforge.net/lists/listinfo/scikit-learn-general


    
------------------------------------------------------------------------------
    Live Security Virtual Conference
    Exclusive live event will cover all the ways today's security and
    threat landscape has changed and how IT managers can respond.
    Discussions
    will include endpoint security, mobile security and the latest in
    malware
    threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
    _______________________________________________
    Scikit-learn-general mailing list
    [email protected]
    <mailto:[email protected]>
    https://lists.sourceforge.net/lists/listinfo/scikit-learn-general



------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/


_______________________________________________
Scikit-learn-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/scikit-learn-general

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Scikit-learn-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/scikit-learn-general

Reply via email to