- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想使用 scikit-learn 的 SVR 模块对 future 事件进行时间序列预测。这是我正在尝试使用的源代码:
import csv
import numpy as np
from sklearn.svm import SVR
import matplotlib.pyplot as plt
plt.switch_backend('newbackend')
seq_num=[]
win=[]
def get_data(filename):
with open(filename, 'r') as csvfile:
csvFileReader = csv.reader(csvfile)
next(csvFileReader) # skipping column names
for row in csvFileReader:
seq_num.append(int(row[0])
win.append(int(row[6]))
return
def predict_win(X, y, x):
win = np.reshape(X,(len(X), 1))
svr_lin = SVR(kernel= 'linear', C= 1e3)
svr_poly = SVR(kernel= 'poly', C= 1e3, degree= 2)
svr_rbf = SVR(kernel= 'rbf', C= 1e3, gamma= 0.1)
svr_rbf.fit(X, y)
svr_lin.fit(X, y)
svr_poly.fit(X, y)
plt.scatter(X, y, color= 'black', label= 'Data')
plt.plot(y, svr_rbf.predict(X), color= 'red', label= 'RBF model')
plt.plot(y,svr_lin.predict(X), color= 'green', label= 'Linear model')
plt.plot(y,svr_poly.predict(X), color= 'blue', label= 'Polynomial model')
plt.xlabel('X, other features')
plt.ylabel('win')
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('net_data.csv')
predicted_win = predict_win(X, y, 29)
我的数据集非常巨大,因此我的 csv 数据集的一部分包含在最后。我对第七栏感兴趣。我想预测第七列中的值何时增加或何时减少。是否可以只查看第七列并进行时间序列预测?对此有任何帮助将不胜感激吗?谢谢!
0.007804347,10.0.0.11:49438,10.0.12.12:5001,32,3796291040,3796277984,10,2147483647,28960,3034,29312
0.007856739,10.0.0.11:49438,10.0.12.12:5001,32,3796293936,3796278008,11,2147483647,29056,2999,29312
0.010605189,10.0.0.11:49438,10.0.12.12:5001,32,3796320000,3796291040,20,2147483647,55040,2969,29312
0.010850907,10.0.0.11:49438,10.0.12.12:5001,32,3796348960,3796305520,30,2147483647,84096,2946,29312
0.013598458,10.0.0.11:49438,10.0.12.12:5001,32,3796377920,3796320000,40,2147483647,113024,2951,29312
0.01368011,10.0.0.11:49438,10.0.12.12:5001,32,3796434392,3796348960,60,2147483647,170880,2956,29312
0.015104265,10.0.0.11:49438,10.0.12.12:5001,32,3796434392,3796363440,70,2147483647,199936,2940,29312
0.016406964,10.0.0.11:49438,10.0.12.12:5001,32,3796490864,3796377920,80,2147483647,220160,2943,29312
0.016465876,10.0.0.11:49438,10.0.12.12:5001,32,3796537200,3796432944,81,80,330240,2925,29312
0.018355321,10.0.0.11:49438,10.0.12.12:5001,32,3796547336,3796434392,81,80,333056,2914,29312
0.020171945,10.0.0.11:49438,10.0.12.12:5001,32,3796603808,3796490864,83,80,382336,2956,29312
0.237314523,10.0.0.11:49438,10.0.12.12:5001,32,3810417728,3809658976,529,396,1775360,7109,29312
0.237409075,10.0.0.11:49438,10.0.12.12:5001,44,3810417728,3809700968,530,397,1859328,7381,29312
0.237486647,10.0.0.11:49438,10.0.12.12:5001,44,3810417728,3809700968,371,371,1960704,7365,29312
0.237807596,10.0.0.11:49438,10.0.12.12:5001,44,3810417728,3809700968,371,371,1980928,7362,29312
0.237989588,10.0.0.11:49438,10.0.12.12:5001,44,3810417728,3809700968,371,371,1989632,7400,29312
0.259123971,10.0.0.11:49438,10.0.12.12:5001,32,3811590608,3811251776,261,260,2267648,5885,29312
0.259174008,10.0.0.11:49438,10.0.12.12:5001,32,3811655768,3811289424,261,260,2267648,5918,29312
0.262546461,10.0.0.11:49438,10.0.12.12:5001,32,3811720928,3811354584,261,260,2267648,5823,29312
最佳答案
好吧,下面的 svm 函数有问题:
第二行win = ...
未使用,会导致错误。删除它。
def predict_win(X, y, x):
win = np.reshape(X,(len(X), 1)) # <----This line
svr_lin = SVR(kernel= 'linear', C= 1e3)
svr_poly = SVR(kernel= 'poly', C= 1e3, degree= 2)
svr_rbf = SVR(kernel= 'rbf', C= 1e3, gamma= 0.1)
svr_rbf.fit(X, y)
svr_lin.fit(X, y)
svr_poly.fit(X, y)
plt.scatter(X, y, color= 'black', label= 'Data')
plt.plot(y, svr_rbf.predict(X), color= 'red', label= 'RBF model')
plt.plot(y,svr_lin.predict(X), color= 'green', label= 'Linear model')
plt.plot(y,svr_poly.predict(X), color= 'blue', label= 'Polynomial model')
plt.xlabel('X, other features')
plt.ylabel('win')
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]
<小时/>
其次,我不知道为什么有一个完整的函数来读取 csv。忽略它并使用 pandas。这是一个可以运行的示例代码:
from sklearn import svm
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
def predict_win(X,y,x):
svr_lin = svm.SVR(kernel='linear',C=1e3)
svr_poly = svm.SVR(kernel='poly',C=1e3, degree=2)
svr_rbf = svm.SVR(kernel='rbf',C=1e3,gamma=0.1)
svr_rbf.fit(X,y)
svr_lin.fit(X,y)
svr_poly.fit(X,y)
plt.plot(y,svr_rbf.predict(X),color='red',label='RBF model')
plt.plot(y,svr_lin.predict(X),color='green',label='Linear model')
plt.plot(y,svr_poly.predict(X),color='blue', label='Polynomial model')
plt.xlabel('X, other features')
plt.ylabel('win')
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]]
df = pd.read_csv('data.csv')
data_np_array = df.values
y = np.ndarray.copy(data_np_array[:,6])
Xleft = np.ndarray.copy(data_np_array[:,:6])
Xright = np.ndarray.copy(data_np_array[:,7:])
X = np.hstack((Xleft,Xright))
x0 = np.ndarray.copy(X[0,:])
xp = predict_win(X,y,x0)
percent_off = [min(data_np_array[0,2],prediction)/max(data_np_array[0,2],prediction) for prediction in xp]
<小时/>
必须完成中间步骤,其中清理导入的数据,将其从数据帧转换为 numpy 数组,复制第七列作为拟合回归,从训练数据中删除它,然后重建一个新数组在安装到 SVR 之前。
df = pd.read_csv('data.csv')
data_np_array = df.values
y = np.ndarray.copy(data_np_array[:,6])
Xleft = np.ndarray.copy(data_np_array[:,:6])
Xright = np.ndarray.copy(data_np_array[:,7:])
X = np.hstack((Xleft,Xright))
让我知道这些是否有效。我刚刚从上面的数据表中取出了几行。
关于python - 预测: Time-series prediction of future events using SVR module,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40357805/
这里有没有人在使用Google Prediction API?为了什么?它“起作用”了吗? 最佳答案 如果您正在寻找实际案例,请查看此案例automatically assigns priority
无论如何,学习R ..: 在简单的x和y回归中,我输入: predict(data1.lm, interval="prediction") 和 predict(data1.lm, interval="
我创建并调整了多个模型,但在尝试预测它们时遇到了问题。我首先按如下方式运行代码来调整 LDA 模型。 library(MASS) library(caret) library(randomForest
问题 我在 R 中训练了一个线性回归来预测 this.target来自 city , 数据框中的变量 data .这个训练是在数据的一个子集上完成的,它由 train.index 指定。 . mode
我正在检查 tf-serving 示例,发现 inception_client.py mnist_client.py 时使用 result = Stub.Predict(request, 10.0)使
我已在 Google ML Engine 中上传了该模型的一个版本,其中包含 saved_model.pb 和一个变量文件夹。当我尝试执行命令时: gcloud ml-engine local pre
请先在我们的 GitHub 存储库中搜索类似问题。如果您找不到类似的示例,您可以使用以下模板: 系统(请填写以下信息): - 操作系统:Ubuntu 18.04 - Python版本:3.6.7 -
我正在研究一个简单的 LL(1) 解析器生成器,我遇到了给定某些输入语法的 PREDICT/PREDICT 冲突问题。例如,给定如下输入语法: E → E + E | P P → 1 我可以
我正在对具有多个预测变量的线性模型的预测值求和,如下例所示,并希望计算该总和的组合方差、标准误差和可能的置信区间。 lm.tree <- lm(Volume ~ poly(Girth,2), data
我是 R 和统计学的新手。所以这个问题可能有点愚蠢,但我想知道 R 中的 predict() 和 predict.lm() 之间是否有任何区别?我认为它们是相同的,但如果它们是相同的,为什么会有两个不
我尝试了针对this question而发布的答案,但是错误没有改变。我试图以相同的方式预处理训练集和测试集。它们来自两个不同的文件,我不确定我的老师是否会把我混合在一起,所以在拆分它们之前进行预处理
使用随机森林包:- #install.packages("randomForest") library(randomForest) 我使用在线代码在我的系统上运行随机森林。我得到了一个具有混淆矩阵和准
我有一个模型 (fit),基于上个月之前的历史信息。现在我想使用我的模型来预测当月的情况。当我尝试调用以下代码时: predicted fit$modelInfo$label [1]“随机森林” 因此
我正在尝试找出应用于列表的操作。我有列表/数组名称预测并执行以下指令集。 predictions[predictions >> a = np.array([1,2,3,4,5]) #define ar
此 R 代码引发警告 # Fit regression model to each cluster y fit$rank 检查 另一种方法是拥有比可用变量更多的参数: fit2 <- lm(y ~
我不是 R 专家。我正在尝试计算多项式模型生成的偏差: f calc.bias(f, polydeg, x))。我使用的整个代码: library(PolynomF) f <- function(x)
谁能帮我解决我的问题?我似乎无法从互联网上得到任何答案。我一直在寻找一整天。所以这是我的问题。我正在使用 opencv4android 2.4.10 和 Android Studio 作为我的 IDE
我可以使用哪种方法来根据姓氏来预测某人的国籍? 我有大量的文字和作者姓氏。我想确定哪些语言是由拉丁语使用者撰写的,哪些文本是由以英语为母语的使用者撰写的,以便研究一组中的某些写作风格模式是否与另一组中
我很好奇克服“冷启动”问题的方法/途径是什么,当新用户或项目进入系统时,由于缺乏有关该新实体的信息,因此进行推荐是一个问题。 我可以考虑做一些基于预测的推荐(例如性别、国籍等)。 最佳答案 您可以冷启
我正在使用零膨胀负二项式模型(包:pscl)对电影通过联系网络(基于电话数据)的传播进行建模 m1 我的变量是: 因变量: 扩散链的长度(计数 [0,36]) 自变量: 电影特征(虚拟变量和连续变量
我是一名优秀的程序员,十分优秀!