Profilo di nicola761

Nome nicola761
Indirizzo email n/a
Messaggi2
  • Calcolo regressione S&P
    Forum >> Programmazione Python >> Calcolo scientifico
    Ciao a tutti, stavo facendo un esercizio dell'autore "Python per la data scienze".

    Facendolo su Spider l'esercizio si conclude correttamente producendo il grafico dello S&P.

    Con lo stesso codice, Python mi dà diversi Warning e conclude con un errore.




    Ecco il codice:

    import numpy, pandas as pd
    import matplotlib, matplotlib.pyplot as plt
    import sklearn.linear_model as lm





    # Get the data
    sap = pd.read_csv("sapXXI.csv").set_index("Date")





    # Select a "linearly looking" part
    sap.index = pd.to_datetime(sap.index)
    sap_linear = sap.ix[sap.index > pd.to_datetime('2010-01-01')]





    # Prepare the model and fit it
    olm = lm.LinearRegression()
    x = numpy.array([x.toordinal() for x in sap_linear.index])[:, numpy.newaxis]
    y = sap_linear['Close']
    olm.fit(x, y)





    # Predict values
    yp = [olm.predict(x.toordinal())0 for x in sap_linear.index]





    # Evaluate the model
    olm_score = olm.score(x, y)





    # Select a nice plotting style
    matplotlib.style.use("ggplot")





    # Plot both data sets
    plt.plot(sap_linear.index, y)
    plt.plot(sap_linear.index, yp)





    # Add decorations


    plt.title("OLS Regression")
    plt.xlabel("Year")
    plt.ylabel("S&P 500 (closing)")
    plt.legend(["Actual", "Predicted"], loc="lower right")
    plt.annotate("Score=%.3f" % olm_score, 
                 xy=(pd.to_datetime('2010-06-01'), 1900))





    plt.savefig("../images/sap-linregr.pdf")
    come dicevo la shell propone warning e l'errore che blocca l'esecuzione:




    Warning (from warnings module):
    File "C:\Users\NicolaAppData\Local\Programs\Python\Python37\lib\site-packages\sklearn\externals\joblib\externals\cloudpickle\cloudpickle.py", line 47
    import imp
    DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses


    Warning (from warnings module):
    File "C:\Users\Nicola\Documents\Learning Machine\sap-linregr.py", line 10
    sap_linear = sap.ix[sap.index > pd.to_datetime('2010-01-01')]
    DeprecationWarning:
    .ix is deprecated. Please use
    .loc for label based indexing or
    .iloc for positional indexing


    See the documentation here:
    http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated
    Traceback (most recent call last):
    File "C:\Users\Nicola\Documents\Learning Machine\sap-linregr.py", line 19, in <module>
    yp = [olm.predict(x.toordinal())0 for x in sap_linear.index]
    File "C:\Users\Nicola\Documents\Learning Machine\sap-linregr.py", line 19, in <listcomp>
    yp = [olm.predict(x.toordinal())0 for x in sap_linear.index]
    File "C:\Users\NicolaAppData\Local\Programs\Python\Python37\lib\site-packages\sklearn\linear_model\base.py", line 213, in predict
    return self._decision_function(X)
    File "C:\Users\NicolaAppData\Local\Programs\Python\Python37\lib\site-packages\sklearn\linear_model\base.py", line 196, in _decision_function
    X = check_array(X, accept_sparse=['csr', 'csc', 'coo'])
    File "C:\Users\NicolaAppData\Local\Programs\Python\Python37\lib\site-packages\sklearn\utils\validation.py", line 540, in check_array
    "if it contains a single sample.".format(array))
    ValueError: Expected 2D array, got scalar array instead:
    array=733776.
    Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.





    Potete aiutarmi?




    Grazie.


    --- Ultima modifica di nicola761 in data 2018-10-08 21:57:19 ---
  • Problema installazione fbprophet
    Forum >> Principianti
    Ciao a tutti, sono alla prime armi e chiedo il primo aiuto.




    Lanciando l'installazione di fbprophet con pip install fbprophet dal Prompt. L'operazione fallisce dando il seguente output:




    Collecting fbprophet
    Using cached https://files.pythonhosted.org/packages/83/a1/a39be1675a62597e4c0d4fdaeb65b14752b8aa8afc92e90edd91614353ab/fbprophet-0.3.post2.tar.gz
    Requirement already satisfied: Cython>=0.22 in c:\users\nicola\appdata\local\programs\python\python37\lib\site-packages (from fbprophet) (0.28.5)
    Collecting pystan>=2.14 (from fbprophet)
    Using cached https://files.pythonhosted.org/packages/6f/a1/fdf8906311733b7894aad1395d4d43afbbc79ca7573a07200eb105c5938c/pystan-2.18.0.0.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "C:\Users\NicolaAppData\Local\Temp\pip-install-vt65armu\pystan\setup.py", line 124, in <module>
    logger.warning("MSVC is not supported")
    NameError: name 'logger' is not defined


    ----------------------------------------
    Command "python setup.py egg_info" failed with error code 1 in C:\Users\NicolaAppData\Local\Temp\pip-install-vt65armu\pystan\




    Grazie per l'aiuto.