Как установить statsmodels в python

от admin

Installing statsmodels¶

The easiest way to install statsmodels is to install it as part of the Anaconda distribution, a cross-platform distribution for data analysis and scientific computing. This is the recommended installation method for most users.

Instructions for installing from PyPI, source or a development version are also provided.

Python Support¶

statsmodels supports Python 3.7, 3.8, and 3.9.

Anaconda¶

statsmodels is available through conda provided by Anaconda. The latest release can be installed using:

PyPI (pip)¶

To obtain the latest released version of statsmodels using pip:

Follow this link to our PyPI page to directly download wheels or source.

For Windows users, unofficial recent binaries (wheels) are occasionally available here.

Obtaining the Source¶

We do not release very often but the main branch of our source code is usually fine for everyday use. You can get the latest source from our github repository. Or if you have git installed:

If you want to keep up to date with the source on github just periodically do:

in the statsmodels directory.

Installation from Source¶

You will need a C compiler installed to build statsmodels. If you are building from the github source and not a source release, then you will also need Cython. You can follow the instructions below to get a C compiler setup for Windows.

If your system is already set up with pip, a compiler, and git, you can try:

If you do not have pip installed or want to do the installation more manually, you can also type:

Or even more manually

statsmodels can also be installed in develop mode which installs statsmodels into the current python environment in-place. The advantage of this is that edited modules will immediately be re-interpreted when the python interpreter restarts without having to re-install statsmodels.

Compilers¶

Linux¶

If you are using Linux, we assume that you are savvy enough to install gcc on your own. More than likely, it is already installed.

Windows¶

It is strongly recommended to use 64-bit Python if possible.

Getting the right compiler is especially confusing for Windows users. Over time, Python has been built using a variety of different Windows C compilers. This guide should help clarify which version of Python uses which compiler by default.

Installing statsmodels on MacOS requires installing gcc which provides a suitable C compiler. We recommend installing Xcode and the Command Line Tools.

Dependencies¶

The current minimum dependencies are:

Cython is required to build from a git checkout but not to run or install from PyPI:

Cython >= 0.29 is required to build the code from github but not from a source distribution.

Given the long release cycle, statsmodels follows a loose time-based policy for dependencies: minimal dependencies are lagged about one and a half to two years. Our next planned update of minimum versions is expected in the first half of 2020.

Optional Dependencies¶

cvxopt is required for regularized fitting of some models.

Matplotlib >= 3 is needed for plotting functions and running many of the examples.

If installed, X-12-ARIMA or X-13ARIMA-SEATS can be used for time-series analysis.

pytest is required to run the test suite.

IPython >= 6.0 is required to build the docs locally or to use the notebooks.

joblib >= 1.0can be used to accelerate distributed estimation for certain models.

Как установить statsmodels в python

Copy raw contents

Copy raw contents

The easiest way to install statsmodels is to install it as part of the Anaconda distribution, a cross-platform distribution for data analysis and scientific computing. This is the recommended installation method for most users.

Instructions for installing from PyPI, source or a development version are also provided.

statsmodels supports Python 3.8, 3.9, and 3.10.

statsmodels is available through conda provided by Anaconda. The latest release can be installed using:

To obtain the latest released version of statsmodels using pip:

Follow this link to our PyPI page to directly download wheels or source.

For Windows users, unofficial recent binaries (wheels) are occasionally available here.

Obtaining the Source

We do not release very often but the main branch of our source code is usually fine for everyday use. You can get the latest source from our github repository. Or if you have git installed:

If you want to keep up to date with the source on github just periodically do:

in the statsmodels directory.

Installation from Source

You will need a C compiler installed to build statsmodels. If you are building from the github source and not a source release, then you will also need Cython. You can follow the instructions below to get a C compiler setup for Windows.

If your system is already set up with pip, a compiler, and git, you can try:

If you do not have pip installed or want to do the installation more manually, you can also type:

statsmodels can also be installed in develop mode which installs statsmodels into the current python environment in-place. The advantage of this is that edited modules will immediately be re-interpreted when the python interpreter restarts without having to re-install statsmodels.

It is usually recommended to use the —no-build-isolation to speed up the build process.

If you are using Linux, we assume that you are savvy enough to install gcc on your own. More than likely, it is already installed.

It is strongly recommended to use 64-bit Python if possible.

Getting the right compiler is especially confusing for Windows users. Over time, Python has been built using a variety of different Windows C compilers. This guide should help clarify which version of Python uses which compiler by default.

Installing statsmodels on MacOS requires installing gcc which provides a suitable C compiler. We recommend installing Xcode and the Command Line Tools.

The current minimum dependencies are:

    >= 3.8 >= 1.18 >= 1.4 >= 1.0 >= 0.5.2

Cython is required to build from a git checkout but not to run or install from PyPI:

    >= 0.29.26 is required to build the code from github but not from a source distribution.

Given the long release cycle, statsmodels follows a loose time-based policy for dependencies: minimal dependencies are lagged about one and a half to two years. Our next planned update of minimum versions is expected in the first half of 2020.

About statsmodels

statsmodels is a Python package that provides a complement to scipy for statistical computations including descriptive statistics and estimation and inference for statistical models.

Documentation

The documentation for the latest release is at

The documentation for the development version is at

Recent improvements are highlighted in the release notes

Backups of documentation are available at https://statsmodels.github.io/stable/ and https://statsmodels.github.io/dev/.

Main Features

Linear regression models:

  • Ordinary least squares
  • Generalized least squares
  • Weighted least squares
  • Least squares with autoregressive errors
  • Quantile regression
  • Recursive least squares

Mixed Linear Model with mixed effects and variance components

  • Logit and Probit
  • Multinomial logit (MNLogit)
  • Poisson and Generalized Poisson regression
  • Negative Binomial regression
  • Zero-Inflated Count models

RLM: Robust linear models with support for several M-estimators.

Time Series Analysis: models for time series analysis

Complete StateSpace modeling framework

Seasonal ARIMA and ARIMAX models

Unobserved Component models

Читать:
Как сделать перенос строки

Markov switching models (MSAR), also known as Hidden Markov Models (HMM)

  • Proportional hazards regression (Cox models)
  • Survivor function estimation (Kaplan-Meier)
  • Cumulative incidence function estimation
  • Principal Component Analysis with missing data
  • Factor Analysis with rotation
  • MANOVA
  • Canonical Correlation

Nonparametric statistics: Univariate and multivariate kernel density estimators

Statistics: a wide range of statistical tests

  • diagnostics and specification tests
  • goodness-of-fit and normality tests
  • functions for multiple testing
  • various additional statistical tests

Imputation with MICE, regression on order statistic and Gaussian imputation

Graphics includes plot functions for visual analysis of data and model results

  • Tools for reading Stata .dta files, but pandas has a more recent version
  • Table output to ascii, latex, and html

Sandbox: statsmodels contains a sandbox folder with code in various stages of development and testing which is not considered «production ready». This covers among others

  • Generalized method of moments (GMM) estimators
  • Kernel regression
  • Various extensions to scipy.stats.distributions
  • Panel data models
  • Information theoretic measures

How to get it

The master branch on GitHub is the most up to date code

Source download of release tags are available on GitHub

Binaries and source distributions are available from PyPi

Binaries can be installed in Anaconda

conda install statsmodels

Installing from sources

See INSTALL.txt for requirements or see the documentation

Contributing

Contributions in any form are welcome, including:

  • Documentation improvements
  • Additional tests
  • New features to existing models
  • New models

for instructions on installing statsmodels in editable mode.

License

Modified BSD (3-clause)

Discussion and Development

Discussions take place on the mailing list

and in the issue tracker. We are very interested in feedback about usability and suggestions for improvements.

Your first Machine Learning Program using StatsModels and Scikit_Learn!

Are you excited yet? ��
You are about to write your first machine learning program using python!

If you haven’t already installed python packages for machine learning, you can find how to do it here! ����

M achine learning in today’s world is all about building models using algorithms that uncovers connections, systems, and organizations to make better decisions without any human intervention. It is primarily concerned with the accuracy and effectiveness of the computer system. Machine learning is considered to be the subset of artificial intelligence.

Getting that out of the way, let’s write our first program!

1. Hydrocarbon Escape:

Download hydrocarbon_data, as this contains the data we’ll be using for this program.

//Understanding the problem
Hydrocarbons are organic compounds found in crude oil and natural gas. Hydrocarbons are made of hydrogens and carbons.

To keep hydrocarbons from escaping from a car, a catalytic converter completes the combustion of unburned hydrocarbons. Hydrocarbons also come from the bacterial decomposition of organic matter, forest fires, and vegetation. Incomplete combustion of gasoline-fueled vehicles and industrial emissions account for 1/6th of all atmospheric hydrocarbons.

While hydrocarbons cause no harmful effects, they can undergo chemical reactions in the presence of sunlight and nitrogen oxides. They can contribute to smog and the formation of toxic formaldehyde.

Today, we will use linear regression to model the escape of hydrocarbons when fuel is pumped into a car.

Our data attributes will include:
Tank Temperature (degrees Fahrenheit)
Petrol Temperature (degrees Fahrenheit)
Initial Tank Pressure (pounds/square inch)
Petrol Pressure (pounds/square inch)
Hydrocarbons Escaping (grams)

We’ll write this program using Statsmodel and Scikit_Learn.

The program begins here!

  1. Open terminal (run as administrator) and open ipython.

2. First, we need to import NumPy, Pandas, and PyPlot from Matplotlib. Then, we display the first ten elements from the hydrocarbon_data file.

NumPy: (According to Wikipedia) NumPy is a library for the Python programming language, adding support for large, multi-dimensional arrays and matrices, along with an extensive collection of high-level mathematical functions to operate on these arrays.

Pandas: (According to Wikipedia) In computer programming, pandas is a software library written for the Python programming language for data manipulation and analysis. In particular, it offers data structures and operations for manipulating numerical tables and time series.

Matplotlib: (According to Wikipedia) Matplotlib is a plotting library for the Python programming language and its numerical mathematics extension NumPy. It provides an object-oriented API for embedding plots into applications using general-purpose GUI toolkits like Tkinter, wxPython, Qt, or GTK+.
PyPlot provides MATLAB like plotting framework.

Explanation:

We are importing essential packages which are used to read/store the hydrocarbon_data in DataFrames (df). We then display the first 10 elements using df.head(n=10).

(Default value of n = 5)

3. Plot the data as independent versus dependent variables.

Explanation:

fig, axs = plt.subplots(1, 4, sharey=True)
It returns a tuple fig, axs which is unpacked in two variables using the notation.
The arguments in subplots, communicate the following about the output figure:
(number_of_rows_in_figure = 1, number_of_columns_in_figure = 4, Should the y-axis be same throughout the figure? =[sharey=True]).

df.plot(kind=’scatter’, x=’ptemp’, y=’hesc’, ax=axs[1])
It plots a scatter graph(kind=’scatter’) on the graph in column 2 of row 1 of figure(ax=axs[1]). Graphing ptemp in x axis and hesc in y axis(x=’ptemp’, y=’hesc’).

Difference between plt.show() and plt.draw()

plt.show(): It displays the current figure that you are working on.

plt.draw(): It re-draws the figure. This allows you to work in interactive mode and, should you have changed your data or formatting, allow the graph itself to change.

4. Now we’ll utilize statsmodels, so let’s begin by importing it.

Statsmodels: is a Python module that provides classes and functions for the estimation of many different statistical models, as well as for conducting statistical tests, and statistical data exploration.

Explanation:

lm = smf.ols(formula = ‘hesc

ttemp’, data=df).fit()
The formula is written with patsy syntax. Data is the data to be used.
smf.ols takes the formula string and the DataFrame, live and returns an OLS object representing the model. The name ols stands for “ordinary least squares.”
fit() method fits the model to the data and returns an object containing the regression results.

5. Now, copy paste the below code line by line.

Hence,
1 unit increase in ttemp is associated with a 0.396703 increase in hesc.
y = 8.153444 + 0.396703 * x
(29) 21.244643 = 8.153444 + 0.396703 * 33

6. You can get the summary by typing,

7. To predict, plot and display ttemp data in the graph.

8. Predicting more data.

9. Plot and display all the predictions.

10. Another prediction.

11. Now we import Scikit_Learn.

12. Copy-paste the below lines one by one.

13. Using scikit to plot a graph.

14. Go ahead and experiment on your own with linear regression and see if you can get a better line model (try with one of the other attributes, 2 different attributes, 3 attributes, and 4 attributes). Watch the R Square value as you change models. For each experiment, give the attributes used, the equation of the line, the R Square value, and how well the model predicts.

Experiment:

Which line model predicted the best?
How many independent attributes are good to use when trying to predict the dependent attributes?

By doing this I hope you have a basic idea of what machine learning is like.

You have successfully written your first machine learning program!
Follow me and give me some claps if this helped you ������ !!

Похожие статьи