python - Python代码返回: Syntaxerror non-keyword after keyword arg

标签 python scikit-learn syntax-error

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)

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

好的,所以我现在已经在互联网上搜索了几个小时,并查看了不同的文档..但是我找不到解决我问题的方法。
如我的标题所述python代码返回以下内容:关键字arg后为Syntaxerror非关键字

最佳答案

gamma=0,1是两个参数,第一个为关键字,第二个为位置参数,该参数无效。您可能需要gamma=0.1来代替。

关于python - Python代码返回: Syntaxerror non-keyword after keyword arg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47915290/

相关文章:

python - 跨多个时间段计算前 10 名或前 X 名列表的有效方法

python - 如何漂亮地打开Tkinter程序?

Python 3.5.2 记录器配置和使用

Python:2 暗淡形状的数组 (1,1024) 被读取为 3 暗淡数组

Python为导入模块中的属性分配本地值

math - 如何获得sklearn中逻辑回归模型的对数似然?

python - R.scale() 和 sklearn.preprocessing.scale() 的区别

javascript - React.js 转译问题。 Babel 构建命令不起作用

php - PHP解析/语法错误;以及如何解决它们

mysql - 如何制作自增INSERT INTO语句?