Skip to content

Local Regression is Missing #3075

Closed
Closed

Description

@aboSamoor

Is local linear regression in scikit? Are you planning to implement that in the future? If not, are contributions welcome in this area?

Activity

  1. pkch commented on Mar 27, 2016

    @pkch

    I assume the OP meant precisely what statsmodels' lowess does. But if I understand correctly, statsmodels combines fit and predict methods into one, and so doesn't allow to predict on new data. Is @agramfort package considered for an eventual addition to scikit-learn? If not, it seems like a rather unfortunate omission.

  2. agramfort commented on Mar 27, 2016

    @agramfort
    Member
  3. pkch commented on Mar 27, 2016

    @pkch

    I thought about the case with one feature, but only because it's so much more common and because in the multi-variate case I'm afraid performance would be a much bigger problem.

  4. naught101 commented on Aug 31, 2016

    @naught101

    The statsmodel version of lowess doesn't have any higher functions, like estimating the error variance of the model. As far as I can tell, such functionality doesn't exist anywhere in the python universe yet. I'm currently using rpy2 to access the R version of loess.

  5. luisvalesilva commented on Oct 13, 2016

    @luisvalesilva

    I'm currently using R's loess through rpy2, just like @naught101. Would love to see it get added to scikit-learn.

  6. amueller commented on Oct 13, 2016

    @amueller
    Member

    @luisvalesilva what's the problem with using the gist or statsmodels? This seems to be used mostly for 1d and so doesn't really fit into scikit-learn? I'm not really familiar though.

    I mean in principal you could do that with nd data, too.. @agramfort what is this usually used for?

  7. luisvalesilva commented on Oct 14, 2016

    @luisvalesilva

    @amueller in my particular case, I need x values in the output different from the observed x values. I am not an expert, though, so there might be other ways. And I do see the point that this doesn't fit scikit-learn too well.

  8. amueller commented on Oct 14, 2016

    @amueller
    Member

    @luisvalesilva sorry I didn't understand your comment.

  9. luisvalesilva commented on Oct 16, 2016

    @luisvalesilva

    @amueller I didn't provide enough information, I'm sorry. What I want to do is this: given a data set with some observed x and y values, generate a close reproduction of the data for new x values in the same range as the original x values. Here's some R code generating a simplified example of the problem.

    Let's say I have the following data.

    # Observed x values
    x <- round(seq(1, 78, 1) * (100/78), 1)
    x
    

    [1] 1.3 2.6 3.8 5.1 6.4 7.7 9.0 10.3 11.5 12.8 14.1
    [12] 15.4 16.7 17.9 19.2 20.5 21.8 23.1 24.4 25.6 26.9 28.2
    [23] 29.5 30.8 32.1 33.3 34.6 35.9 37.2 38.5 39.7 41.0 42.3
    [34] 43.6 44.9 46.2 47.4 48.7 50.0 51.3 52.6 53.8 55.1 56.4
    [45] 57.7 59.0 60.3 61.5 62.8 64.1 65.4 66.7 67.9 69.2 70.5
    [56] 71.8 73.1 74.4 75.6 76.9 78.2 79.5 80.8 82.1 83.3 84.6
    [67] 85.9 87.2 88.5 89.7 91.0 92.3 93.6 94.9 96.2 97.4 98.7
    [78] 100.0

    # Observed y values (use random data set included with base R)
    y <- LakeHuron[0:length(x)]
    
    plot(x, y, type = 'l')
    

    observed

    I need to get y values for the sequence of integers between 1 and 100. These will be my new x values.

    # Build model and then use it to predict y values
    model <- loess(y ~ x, span = 0.07)
    
    new_x <- seq(1, 100, 1)
    new_x
    

    [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
    [18] 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
    [35] 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
    [52] 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
    [69] 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
    [86] 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100

    new_y <- predict(model, new_x)
    
    plot(new_x, new_y, type = 'l')
    

    predicted

    In my real application, I do something like this for 1000s of similar cases and then calculate the mean value of y for each x value.

    This may be a little out of place here, sorry about that! But I would be very interested in alternative ways to do this.

  10. ashimb9 commented on Oct 27, 2017

    @ashimb9
    Contributor

    @amueller They can be used for multivariate data. As is discussed here, the difference appears to be in the particular implementation, where "lowess" have been implementations for 1D predictor case and "loess" for the multivariate case.

    PS: My apologies for joining the party late, but I figured I'd post since the issue had not been closed

    EDIT: Here is another useful discussion of the lowess vs loess implementation in R.

  11. histed commented on Jan 14, 2020

    @histed

    I'm currently using R's loess through rpy2, just like @naught101. Would love to see it get added to scikit-learn.

    Same here, though skmisc's loess might fit better in statsmodels.

    The current skmisc loess implementation is 1d. It's used for similar applications as scikit-learn's kernel estiamators in 1d.

    @amueller If sklearn would be interested, I can look into helping get skmisc.loess fixed up for submission to sklearn. If you aren't interested, let us know and we can ask statsmodels

  12. naught101 commented on Jan 15, 2020

    @naught101

    would you restrict the method to data with only one feature? I could see such a non-parametric regression method in a generalized additive model (GAM) module based on backfitting. Thoughts?

    Cross-referencing: #3482

  13. niknow commented on Feb 7, 2021

    @niknow

    It is my understanding that local regression is not supported directly in scikit-learn at the moment. However, one can combine some existing modules from scikit-learn, numpy and scipy to build a custom regressor in scikit-learn, which can then be used with the same interface as the LinearRegression model. That is a bit of work, but not completely out of reach. I did that a while back and put a prototype with some unit tests and a notebook that explains the mathematical background a bit in my repository here:

    https://github.com/niknow/machine-learning-examples/tree/master/local_regression

    Is this what you guys are looking for? It does work with multivariate input data and supports local polynomial regression of any degree.

    @amueller If so, would there still be any interest in this? I'd be more than happy to give back to the community and submit this as a proper scikit-learn model via a pull request.

  14. amueller commented on Apr 6, 2021

    @amueller
    Member

    I think it would be great to have, but one issue is always finding reviewers. Not sure if @naught101 is still interested and/or @agramfort ?

  15. naught101 commented on Apr 6, 2021

    @naught101

    @amueller I don't think I am very qualified to give a review of the stats implementation, unfortunately. I'm happy to do some testing though.

  16. amueller commented on Apr 6, 2021

    @amueller
    Member

    Also maybe @thomasjpfan who looked into GAMs? Though this sounds closer to MARS?

  17. agramfort commented on Apr 7, 2021

    @agramfort
    Member

    I am not an expert on this matter but I have a look to an implementation.

  18. lorentzenchr commented on Feb 28, 2026

    @lorentzenchr
    Member

    I would say we have

    Pipeline(
        [
            (
                "preprocessor",
                ColumnTransformer(
                    [
                        ("poly", PolynomialFeatures(degree=2) ,["col_A", "col_B"]),
                        ("bspline", SplineTransformer(degree=3, n_knots=10) ,["col_C", "col_D"]),
                    ]
                )
            ),
            ("regressor", RidgeCV(),
        ]
    )

    The missing features are penalties on B-Spline differences as requested in #20760, or full GAMs #3482.
    I also have concerns about runtime and memory requirements of kernel regression.

    Therefore, I close.

    On top, there are

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions