Linear regression with python

Asked

Viewed 3,673 times

3

I need to do the linear regression calculation, but I read that there is no possibility to use/install scipy in windows. Is there any other scipy-like library to perform this kind of calculation? Or if there is any way to install scipy in windows, it is also welcome! thanks.

  • Ever tried to make pip install scipy at the prompt?

  • So Anderson, quiet? I tried, he does not install, I read on the scipy site and there says that it is not possible to install in windows. I downloaded some whl files and tried to install by Pip and it was not also.

  • No - scipy is what you have to use - has how to use Windows yes. And if you didn’t, it would be better for you to set up Pyton and Scipy on a virtual machine (or in microsoft’s new scheme of having an Ubuntu hybrid pr inside Windows from the windows app store) than to try to go too far using other tool sets.

2 answers

3

According to the own documentation of scipy it doesn’t turn very well in Windows because it has some dependencies that only work in linux and mac

Alternatively, I recommend using sklearn, she is a very good lib working with Learning machine, and also has good documentation plus several examples.

to install it you can:

pip install -U scikit-learn

or if using anaconda:

conda install scikit-learn

I made an example using the numpy (to work with arrays) and the matplot (to work with graphics) To install:

pip install numpy

python -m pip install -U pip setuptools

python -m pip install matplotlib

In anaconda usually these libs already come installed.

Below is an example of creating a linear regression with the sklearn

    import matplotlib.pyplot as plt
    import numpy as np
    from sklearn import linear_model

    #Logica x = x*10 + acc
    #acc = acc + 5
    #acc inicia em 0

    #dataSet treino
    #1 - 10 + 0 = 10
    #2 - 20 + 5 = 25
    #3 - 30 + 10 = 40
    #4 - 40 + 15 = 55
    x_train = np.array([ [1], [2], [3], [4] ]);
    y_train = np.array([ 10, 25, 40, 55 ]);

    #dataSet teste
    #5 - 50 + 20 = 70
    #6 - 60 + 25 = 85
    #7 - 70 + 30 = 100
    #8 - 80 + 35 = 115
    x_test = np.array([ [5], [6], [7], [8] ])
    y_test = np.array([ 70, 85, 100, 115 ])

    #cria o modelo e faz o treinamento (fit)
    model = linear_model.LinearRegression().fit(x_train, y_train)

    #exibe algumas informações
    print('Coeficientes: \n', model.coef_)
    print("Erro médio quadrado: %.2f" % np.mean((model.predict(x_test) - y_test) ** 2))
    print('variância de score: %.2f' % model.score(x_test, y_test))

    #monta o plot para exibição do resultado
    plt.scatter(x_test, y_test,  color='black')
    plt.plot(x_test, model.predict(x_test), color='blue', linewidth=3)
    plt.xticks(())
    plt.yticks(())
    plt.show()

This code will generate a graph in this way:inserir a descrição da imagem aqui

An example of the documentation of the sklearn with linear regression applied on diabetes tests:

Linear Regression Example

3


From what I read on scipy runs on Windows yes.

[Google Translate] For most users, especially on Windows, the easiest way to install Scipy stack packages is to download one of these Python distributions, which include all major packages: Anaconda, Enthought Canopy, Python(x, y), Winpython, Pyzo

Try one of those:

  • Anaconda: A free distribution for the Scipy stack. Compatible with Linux, Windows and Mac.
  • Enthought Canopy: Free and commercial versions include the core Scipy stack packages. Supports Linux, Windows and Mac.
  • Python(x, y): A free distribution including the Scipy stack, based around the Spyder IDE. Windows only.
  • Winpython: A free distribution including the Scipy stack. Windows only.
  • Pyzo: A free distribution based on Anaconda and the interactive IEP development environment. Supports Linux, Windows and Mac.
  • depends on installing python on its machine, if it is using pure python it will be tense.. Now if you are using anaconda or some other api over python there are these versions. do not recommend him uninstall his environment that is already configured to install and configure another environment just to run a linear regression... but it depends a lot on the end that he will use... as said the sklearn is a much more powerful api than scipy, but again depends on the purpose it will use

  • and as I said ele não roda muito bem em Windows, can even run as they have made some dependency changes to rodar in windows, but in the documentation itself they do not guarantee full functionality, the problem itself is not the scipy but the dependencies that scipy uses

  • By default the anaconda does not come with scipy installed, scipy installation is done as follows: conda install -c anaconda scipy=0.19.0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.