Python generalized linear model poisson
Generalized Linear Model with a Poisson distribution. Show This regressor uses the ‘log’ link function. Read more in the User Guide. New in version 0.23. Parameters:alphafloat, default=1Constant that multiplies the penalty term and thus determines the regularization strength.
Specifies if a constant (a.k.a. bias or intercept) should be added to the linear predictor (X @ coef + intercept). max_iterint, default=100The maximal number of iterations for the solver. Values must be in the range Stopping criterion. For the lbfgs solver, the iteration will stop when If set to For the lbfgs solver set verbose to any positive number for verbosity. Values must be in the range Estimated coefficients for the linear predictor ( Intercept (a.k.a. bias) added to linear predictor. n_features_in_intNumber of features seen during fit. New in version 0.24. feature_names_in_ndarray of shape (n_features_in_ ,)Names of features seen during
fit. Defined only when New in version 1.0. n_iter_intActual number of iterations used in the solver. Examples >>> from sklearn import linear_model >>> clf = linear_model.PoissonRegressor() >>> X = [[1, 2], [2, 3], [3, 4], [4, 3]] >>> y = [12, 17, 22, 21] >>> clf.fit(X, y) PoissonRegressor() >>> clf.score(X, y) 0.990... >>> clf.coef_ array([0.121..., 0.158...]) >>> clf.intercept_ 2.088... >>> clf.predict([[1, 1], [3, 4]]) array([10.676..., 21.875...]) Methods
DEPRECATED: Attribute Ensure backward compatibility for the time of deprecation. fit(X, y, sample_weight=None)[source]¶Fit a Generalized Linear Model. Parameters:X{array-like, sparse matrix} of shape (n_samples, n_features)Training data. yarray-like of shape (n_samples,)Target values. sample_weightarray-like of shape (n_samples,), default=NoneSample weights. Returns:selfobjectFitted model. get_params(deep=True)[source]¶Get parameters for this estimator. Parameters:deepbool, default=TrueIf True, will return the parameters for this estimator and contained subobjects that are estimators. Parameter names mapped to their values. predict(X)[source]¶Predict using GLM with feature matrix X. Parameters:X{array-like, sparse matrix} of shape (n_samples, n_features)Samples. Returns:y_predarray of shape (n_samples,)Returns predicted values. score(X, y, sample_weight=None)[source]¶Compute D^2, the percentage of deviance explained. D^2 is a generalization of the coefficient of determination R^2. R^2 uses squared error and D^2 uses the deviance of this GLM, see the User Guide. D^2 is defined as \(D^2 = 1-\frac{D(y_{true},y_{pred})}{D_{null}}\), \(D_{null}\) is the null deviance, i.e. the deviance of a model with intercept alone, which corresponds to \(y_{pred} = \bar{y}\). The mean \(\bar{y}\) is averaged by sample_weight. Best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). Parameters:X{array-like, sparse matrix} of shape (n_samples, n_features)Test samples. yarray-like of shape (n_samples,)True values of target. sample_weightarray-like of shape (n_samples,), default=NoneSample weights. Returns:scorefloatD^2 of self.predict(X) w.r.t. y. set_params(**params)[source]¶Set the parameters of this estimator. The method works on simple estimators as well as on nested objects (such as Estimator parameters. Returns:selfestimator instanceEstimator instance. Examples using sklearn.linear_model.PoissonRegressor¶Is Poisson a generalized linear model?A Poisson Regression model is a Generalized Linear Model (GLM) that is used to model count data and contingency tables. The output Y (count) is a value that follows the Poisson distribution. It assumes the logarithm of expected values (mean) that can be modeled into a linear form by some unknown parameters.
How do I fit a GLM model in python?To fit a model we first need to describe the model using the model class glm. Then the method fit is used to fit the model. Very detailed results of the model fit can be analyzed via the summary method, and finally, we can compute predictions using the predict method.
What is a generalized Poisson model?Generalized Poisson Regression (GPR) is one method that can handle cases of overdispersion and underdispersion. The GPR model is used to estimate regression parameters. Many articles proposed to use only Maximum Likelihood Estimation (MLE) to estimate the parameters of GPR.
|