如果我有自变量[x1,x2,x3]如果我在sklearn中拟合线性回归,它会给我这样的东西:
y = a*x1 + b*x2 + c*x3 + intercept
Run Code Online (Sandbox Code Playgroud)
poly = 2的多项式回归会给我类似的东西
y = a*x1^2 + b*x1*x2 ......
Run Code Online (Sandbox Code Playgroud)
我不希望像x1 ^ 2那样拥有二度学位.
我怎样才能得到
y = a*x1 + b*x2 + c*x3 + d*x1*x2
Run Code Online (Sandbox Code Playgroud)
如果x1和x2具有大于某个阈值j的高相关性.
import dataset
db = dataset.connect(....)
table = db[...]
Run Code Online (Sandbox Code Playgroud)
当我尝试在Mysql表中插入一些值时,发生了此错误.
我要插入表中的示例值:
print("Buy", ticker, price, date, OType, OSize)
Buy AAPL 93.4357142857 2016-05-12 Market 200
data = dict(Order_Side='Buy',Ticker=ticker, Price=price,
Order_Date= date, Order_Type = OType, Volume = OSize )
table.insert(data)
Run Code Online (Sandbox Code Playgroud)
错误信息:
Traceback (most recent call last):
File "<ipython-input-3-b7ab0c98f72f>", line 1, in <module>
runfile('C:/Users/SwigelUser/Documents/GitHub/Trading/Strategies/strat_MA_ExecTest.py', wdir='C:/Users/SwigelUser/Documents/GitHub/Trading/Strategies')
File "C:\Users\SwigelUser\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 880, in runfile
execfile(filename, namespace)
File "C:\Users\SwigelUser\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/SwigelUser/Documents/GitHub/Trading/Strategies/strat_MA_ExecTest.py", line 69, in <module>
MA_Stra(start_length=7,end_length=10,start_date=date(2016,5,12),end_date=date(2016,6,18))
File "C:/Users/SwigelUser/Documents/GitHub/Trading/Strategies/strat_MA_ExecTest.py", line 66, in …Run Code Online (Sandbox Code Playgroud) 我有一个数据集,第一列是Date,Second列是Price.交易日是交易日.
我想返回一个如下所示的表:
如果日期是从2006年开始的每个月,价格MA是过去N个月的平均价格.(N = [1,2,3,4,5,6])
例如:如果我想在2006年1月1日N = 1 Ma应该是去年12月的平均价格如果N = 2 Ma应该是去年11月和12月的平均价格
我已经阅读了一些关于从datetime和groupby提取月份的解决方案.但不知道如何将它们组合在一起.
您可以通过此链接访问数据集https://drive.google.com/file/d/0B9Hd-26lI95ZeVU5cDY0ZU5MTWs/view?usp=sharing
我的任务是预测行业基金的价格变动.它上升或下降多少并不重要,我只想知道它是上升还是下降.所以我将其定义为分类问题.
由于这个数据集是一个时间序列数据,我遇到了很多问题.我读过有关这些问题的文章,比如我不能使用k-fold交叉验证,因为这是时间序列数据.您不能忽略数据的顺序.
我的代码如下:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import datetime
from sklearn.linear_model import LinearRegression
from math import sqrt
from sklearn.svm import LinearSVC
from sklearn.svm import SVCenter code here
lag1 = pd.read_csv(#local file path, parse_dates=['Date'])
#Trend : if price going up: ture, otherwise false
lag1['Trend'] = lag1.XLF > lag1.XLF.shift()
train_size = round(len(lag1)*0.50)
train = lag1[0:train_size]
test = lag1[train_size:]
variable_to_use= ['rGDP','interest_rate','private_auto_insurance','M2_money_supply','VXX']
y_train = train['Trend']
X_train = train[variable_to_use]
y_test = test['Trend']
X_test = test[variable_to_use] …Run Code Online (Sandbox Code Playgroud) python ×5
scikit-learn ×2
datetime ×1
mysql ×1
numpy ×1
pandas ×1
regression ×1
time-series ×1