sklearn: How to reset a Regressor or classifier object in sknn

后端 未结 2 1577
借酒劲吻你
借酒劲吻你 2021-02-20 14:43

I have defined a regressor as follows:

nn1 = Regressor(
layers=[
    Layer(\"Rectifier\", units=150),
    Layer(\"Rectifier\", units=100),
    Layer(\"Linear\")]         


        
相关标签:
2条回答
  • 2021-02-20 14:43

    sklearn.base.clone should achieve what you're looking to achieve

    0 讨论(0)
  • 2021-02-20 15:10

    The pattern that I use for cross validation instantiates a new classifier for each training/test pair:

    from sklearn.cross_validation import KFold
    
    kf = KFold(len(labels),n_folds=5, shuffle=True)
    for train, test in kf:
        clf = YourClassifierClass()
        clf.fit(data[train],labels[train])
        # Do evaluation with data[test] and labels[test]
    

    You can save your current best classifier in a separate variable and access its parameters after cross validation (this is also useful if you want to try different parameters).

    0 讨论(0)
提交回复
热议问题