如何使用具有特征值作为特征的SVM以得到结果?

时间:2018-08-05 17:28:41

标签: python machine-learning svm

为什么svm结果没有结果?

如何计算测试数据正确的结果?

是否有任何方法或方程式来验证数据是否适合SVM进行预测? 还是神经网络来预测?或Gradient Boost来预测?

说明: 我使用特征值作为特征并在匹配未来值时标记为1, 并将其余的标签标记为0

训练20行数据并测试20行数据

如果考虑在10美元的范围内上涨而在10美元的范围内下跌,则每增量为0.1美元,因此一天有200个训练数据

google('example.com test', function (err, res){
  if (err) console.error(err)

  var link = res.links[0].link.toString();
  console.log(res.links[0].link)

});

(async () => {
  const browser = await puppeteer.launch({headless: false});
  const page = await browser.newPage();

  await page.goto(link, {waitUntil: 'networkidle2'});

  const m = page.mouse
  await m.click(110,420)

  browser.on('targetcreated',  pageOpened => {
      console.log('1');
  });
  await page.waitForNavigation({waitUntil: 'load'});
  let url = await page.url()
  console.log(url)
  fs.appendFile('saved.txt', url, function (err) {
    if (err) throw err;
    console.log('Saved!');
  });

})();

如果匹配,结果中至少应有一个

from numpy import linalg as LA
import numpy as np
import matplotlib.pyplot as plt

import sys
import os
import pandas as pd
import datetime as dt
import re
import numpy as np
from dateutil import parser
import datetime

from sklearn import datasets
import matplotlib.pyplot as plt
from sklearn import svm
from sklearn.externals import joblib
from sklearn import metrics
from sklearn.model_selection import learning_curve
from sklearn.svm import SVC
from sklearn.model_selection import validation_curve

currentdirectory = os.getcwd()
data = pd.read_excel(os.path.join(currentdirectory,"0005.HK2017.xls"), '0005.HK')
df = pd.DataFrame()
df = df.append(data)

ii = 1
jj = df['Close'][1:].tolist()
n = 0
y_train = []
x_train = []
testing = 20
for i in range(1+testing, 10+testing):
    for j in range(1, 100):
        w, v = LA.eig(np.array([[jj[i+0]+j*0.1,jj[i+1],jj[i+2]], [jj[i+3],jj[i+4],jj[i+5]],[jj[i+6],jj[i+7],jj[i+7]]]))
        x_train.append(list(w))
        if jj[i+0]+j*0.1 == jj[i-1]:
            y_train.append(1)
        else:
            y_train.append(0)
    for j in range(1, 100):
        w, v = LA.eig(np.array([[jj[i+0]-j*0.1,jj[i+1],jj[i+2]], [jj[i+3],jj[i+4],jj[i+5]],[jj[i+6],jj[i+7],jj[i+7]]]))
        x_train.append(list(w))
        if jj[i+0]-j*0.1 == jj[i-1]:
            y_train.append(1)
        else:
            y_train.append(0)

#clf = svm.SVC(kernel='linear')
clf = svm.SVC()
clf.fit(x_train, y_train)

y_test = []
x_test = []
testing = 0
for i in range(1+testing, 10+testing):
    for j in range(1, 100):
        w, v = LA.eig(np.array([[jj[i+0]+j*0.1,jj[i+1],jj[i+2]], [jj[i+3],jj[i+4],jj[i+5]],[jj[i+6],jj[i+7],jj[i+7]]]))
        x_test.append(list(w))
        if jj[i+0]+j*0.1 == jj[i-1]:
            y_test.append(1)
        else:
            y_test.append(0)
    for j in range(1, 100):
        w, v = LA.eig(np.array([[jj[i+0]-j*0.1,jj[i+1],jj[i+2]], [jj[i+3],jj[i+4],jj[i+5]],[jj[i+6],jj[i+7],jj[i+7]]]))
        x_test.append(list(w))
        if jj[i+0]-j*0.1 == jj[i-1]:
            y_test.append(1)
        else:
            y_test.append(0)

result = clf.predict(np.asarray(x_test))
metrics.f1_score(y_test, result, average='macro')

np.savetxt("runningresult.csv", result, delimiter=",")
np.savetxt("y_test.csv", y_test, delimiter=",")

0 个答案:

没有答案