codes.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:jamespy_py3 作者: jskDr 项目源码 文件源码
def cross_val_score_loo( lm, X, y):
    """
    mean_square_error metric is used from sklearn.metric.

    Return 
    --------
    The mean squared error values are returned. 
    """
    # Transformed to array if they are list, np.mat
    X = np.array( X)
    y = np.array( y)
    # Later, assert can be used to define the size of X and y

    if len( y.shape) == 1:
        y = np.array( [y]).T

    kf = cross_validation.LeaveOneOut( y.shape[0])
    # flatterned error vectors for each point are stored in this vector.
    errors_l = list()
    for tr, te in kf:
        lm.fit( X[tr,:], y[tr,:])
        yp = lm.predict( X[te, :])
        errors_l.extend( (y[te,:] - yp).flatten().tolist())

    return errors_l
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号