2017-12-20 20 views
0
import csv 
import numpy as np 
from sklearn.svm import SVR 
import matplotlib.pyplot as plt 

dates = [] 
prices = [] 

def get_data(filename): 
    with open(filename, 'r') as csvfile: 
     csvFileReader = csv.reader(csvfile) 
     next(csvFileReader) 
     for row in csvFileReader: 
      dates.append(int(row[0].split('-')[0])) 
      prices.append(float(row[1])) 
    return 

def predict_price(dates, prices, x): 
    dates = np.reshape(dates,(len(dates), 1)) 

    svr_rbf = SVR(kernel='rbf', C=1e3, gamma=0,1) 
    svr_lin = SVR(kernel='linear', C=1e3) 
    svr_poly = SVR(kernel='poly', C=1e3, degree=2) 
    svn_lin.fit(dates, prices) 
    svr_poly.fit(dates, prices) 
    svr_rbf.fit(dates, prices) 


    plt.scatter(dates, prices, color = 'black', label = 'Data') 
    plt.plot(dates, svr_rbf.predict(dates), color = 'red', label = 'RBF model') 
    plt.plot(dates, svr_lin.predict(dates), color = 'green', label = 'linear model') 
    plt.plot(dates, svr_poly.predict(dates), color = 'blue', label = 'polynomial model') 
    plt.xlabel('Date') 
    plt.xlabel("Price") 
    plt.title('Support Vector Regression') 
    plt.legend() 
    plt.show() 

    return svr_rbf.predict(x)[0], svr_lin.predict(x)[0], svr_poly.predict(x)[0] 

get_data('aapl.csv') 

predicted_price = predict_price(dates, prices, 29) 

print (predicted_price) 

OUTPUT:ので、私は今、時間のためのインターネットを検索し、別のドキュメントで見ているオーケーPythonコードを返します:キーワード引数の後にSyntaxErrorが非キーワード

File "predictstocks.py", line 21 
    svr_rbf = SVR(kernel='rbf', C=1e3, gamma=0,1) 
SyntaxError: non-keyword arg after keyword arg 

..しかし、私は見つけるカント私の問題の解決策。 私のタイトルはPythonのコードがこれを返す言うように:にSyntaxError非キーワードキーワード引数の後に

+1

あなたの質問に完全なエラーを引用符で含めてください。 'SVR'の定義は何ですか? [良い質問をするにはどうすればいいですか?](https://stackoverflow.com/help/how-to-ask) – Galen

+1

stackoverflow検索ボックスに「keyword argの後にSyntaxerror非キーワードを入力する」と入力すると、77個の質問が表示されます。この質問をする前に、エラーの意味を説明しているかどうかを調べるために、 –

+1

に 'scikit-learn'タグが必要ですか? http://scikit-learn.org/stable/modules/generated/sklearn.svm.SVR.html、 'gamma:float' – davedwards

答えて

1

gamma=0,1は二つの引数、キーワード、無効である第二の位置、最初のものです。おそらくgamma=0.1が代わりに必要です。

+0

おかげで、私は愚かな気分になりました。 – LucidTruth

関連する問題