小编Dyl*_*lan的帖子

如何在Python sklearn中添加交互项

如果我有自变量[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的高相关性.

python regression linear-regression scikit-learn

12
推荐指数
3
解决办法
1万
查看次数

'numpy.float64'对象没有属性'translate'在Python中将值插入Mysql

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)

python mysql

9
推荐指数
3
解决办法
7736
查看次数

如何获得熊猫过去几个月的移动平均值

我有一个数据集,第一列是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提取月份的解决方案.但不知道如何将它们组合在一起.

python datetime pandas

8
推荐指数
2
解决办法
5077
查看次数

时间序列分类

您可以通过此链接访问数据集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 classification machine-learning time-series

6
推荐指数
1
解决办法
1775
查看次数

在 python/sklearn 中获取某个类的概率值列

在 sklearn 中使用 randomforest 进行二元分类时。我知道我可以clf.predict(X)用来获得预测的课程。当我使用时clf.predict_proba(X),我得到一个如下所示的数组: 在此处输入图片说明

我认为第一列表示预测的概率?我怎样才能得到一列,该列的概率为 1?

python numpy random-forest scikit-learn

2
推荐指数
1
解决办法
3631
查看次数