Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options answers only not deleted user 7486

Python is a programming language commonly used for machine learning. Use this tag for any *on-topic* question that (a) involves `Python` either as a critical part of the question or expected answer, & (b) is not *just* about how to use `Python`.

1 vote

Breusch Pagan test in Python

The Breusch-Pagan test aims to detect heteroscedasticity in a regression model (the presence of non-constant variance in the error terms). The statsmodels.stats.diagnostic.het_breuschpagan function re …
Robert Long's user avatar
  • 68.5k
10 votes
Accepted

Difference between manifest and observed variables

I agree that this is confusing. Manifest variables and "observed" variables are both observed, in the sense that they are part of the input dataset, and not latent variables. The distinction made in t …
Robert Long's user avatar
  • 68.5k
8 votes

How to determine the best fit slope of a line?

First, the python code for the 1st equation does not implement it correctly. … m=\frac{\sum_{i=0}^{n}(x_i - \bar{x})(y_i - \bar{y})}{\sum_{i=0}^{n}(x_i - \bar{x}^2)}$$ It's $$ m=\frac{\sum_{i=0}^{n}(x_i - \bar{x})(y_i - \bar{y})}{\sum_{i=0}^{n}(x_i - \bar{x})^2} $$ So in (Num)Python
Robert Long's user avatar
  • 68.5k
1 vote

Linear mixed-effect model analysis via python

I am not very experienced with SPSS but If you want to ensure consistency between the two, double-check that Python might handle categorical variables differently in terms of reference categories and dummy … However, to the best of my knowledge, these options are not available in the mixedlm implementation from statsmodels in Python. …
Robert Long's user avatar
  • 68.5k
3 votes

Statsmodels: What can cause LinAlg error?

A "singular matrix" error while fitting mixed models can have several causes and there is not enough information given in the question to accurately diagnose the problem in this case. You mention the …
Robert Long's user avatar
  • 68.5k
3 votes

Calculating R^2 for a linear mixed model in python

statsmodels and MixedLM in Python do not provide $R^2$ statistics, so you would need to manually extract the variance components from your mixed effects model to compute these values. …
Robert Long's user avatar
  • 68.5k
13 votes
Accepted

Can't decide if my data is normally distributed

You seem to have quite a large sample size which is probably why the Shapiro-Wilk test returns a small p-value. In general statistical tests for normality are not a great idea in large part for this v …
Robert Long's user avatar
  • 68.5k
8 votes

Why do my bootstrapped coefficient standard errors differ from statsmodels standard errors

With a large dataset like yours (20,640 observations), the asymptotic assumptions should hold reasonably well, making the bootstrap and OLS standard errors similar unless there are issues: The bootstr …
Robert Long's user avatar
  • 68.5k
5 votes
Accepted

Using n linear regression models for different subsets vs using one model for the entire dat...

You won't have to if you don't split the dataset Is there a python/sklearn implementation of my idea? … It's the type of mistaken thing people do in data science, and Python is used a lot in data science. However, here we try to guide people into a better way of doing things. …
Robert Long's user avatar
  • 68.5k
2 votes
Accepted

Implementations of Lasso in Python and R?

LASSO in Python With Python, in my experience, the most common implementation of LASSO (Least Absolute Shrinkage and Selection Operator) is provided by the scikit-learn library. … For Python, scikit-learn's LASSO is the most straightforward and commonly used implementation, with a solid and efficient coordinate descent algorithm. …
Robert Long's user avatar
  • 68.5k
2 votes
Accepted

Modeling a functional relationship with Constrained Gaussian Process regression

Here's one way to do this in Python: 1. … The pygam library in Python can do this. Constrained Optimisation Models: These can enforce bounds directly during the training process. The scipy.optimize library can do this. …
Robert Long's user avatar
  • 68.5k
4 votes
Accepted

Correlation between numeric variables of different meaning

A zip code would usually be treated as categorical, since there is (presumably) no meaning to the actual value and difference between the numbers, or ordering. The year of building would usually be …
Robert Long's user avatar
  • 68.5k
3 votes

Linear mixed effect model in statsmodel package

The statsmodels package in python can fit such a model import statsmodels.api as sm import statsmodels.formula.api as smf data = sm.datasets.get_rdataset("dietox", "geepack").data md = smf.mixedlm("Weight …
Robert Long's user avatar
  • 68.5k
5 votes
Accepted

Why does PyTorch Linear allow multiple output dimensions?

One use case I can think of is multivariate regression,as opposed to multvariable regression, the former being a model with more than 1 outcome variable, whereas the latter being a model with one outc …
Robert Long's user avatar
  • 68.5k
5 votes
Accepted

Calculating AIC & BIC

There are several of packages in R that can fit them, and since the R ecosystem is much more mature than that for python (and R is designed specifically for statistics whereas python is a general purpose … If you want to stay within python then you can still call R functions from python using the rpy2 python package: https://rpy2.github.io/doc/v2.9.x/html/introduction.html Edit: I really would recommend …
Robert Long's user avatar
  • 68.5k

15 30 50 per page