Quantcast
Channel: Data Science, Analytics and Big Data discussions - Latest topics
Viewing all articles
Browse latest Browse all 4448

Time-series: Predicting future events using SVR module

$
0
0

@arman wrote:

Here is my source code, but not working as i expected it:

import csv
import numpy as np
from sklearn.svm import SVR
import matplotlib.pyplot as plt

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[1]))
    return

def predict_win(seq_num, win, x):
    win = np.reshape(seq_num,(len(seq_num), 1)) # converting to matrix of n 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(seq_num, win)
    svr_lin.fit(seq_num, win)
    svr_poly.fit(seq_num, win)

    plt.scatter(seq_num, win, color= 'black', label= 'Data')
    plt.plot(win, svr_rbf.predict(seq_num), color= 'red', label= 'RBF model')
    plt.plot(win,svr_lin.predict(seq_num), color= 'green', label= 'Linear model')
    plt.plot(win,svr_poly.predict(seq_num), color= 'blue', label= 'Polynomial model')
    plt.xlabel('Seq Number')
    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(seq_num, win, 29)

I want to perform time-series prediction of future events using SVR module from scikit-learn. My dataset is very huge and so a portion of my csv dataset is included here. The whole dataset is attached in .csv format. I am interested in the 7th column. I wanted to perform a time-series prediction when the values in the 7th column increase or when it decreases. Is it possible to look into the 7th column ONLY and do the prediction?

Any help with this? Thanks!

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

net_data.csv (1.4 MB)

Posts: 6

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 4448

Trending Articles