According to own documentation of scipy
it does not work very well in Windows
because it has some dependencies that work only in linux
and mac
As an alternative, I recommend using sklearn , it is a very good lib working with machine learning, and it also has a good documentation as well as several examples.
To install it you can:
pip install -U scikit-learn
or if you use anaconda:
conda install scikit-learn
I made an example using numpy (to work with arrays) and matplot (to work with graphics)
To install:
pip install numpy
python -m pip install -U pip setuptools
python -m pip install matplotlib
In anaconda these libs are usually already installed.
Below is the example of creating a linear regression with 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 like this:
There is also an example of the documentation of sklearn
with linear regression applied on diabetes tests:
Linear Regression Example