main_ml.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:svm 作者: fzn0728 项目源码 文件源码
def tune_para(dataframe, i):
    # To apply an classifier on this data, we need to flatten the image, to
    # turn the data in a (samples, feature) matrix:
    columns = ['SMA_10','Momentum','stoch_K','WMA_10','MACD','A/D','Volume']
    X = dataframe[columns].as_matrix()
    y = dataframe['Adj Close'].as_matrix()
    X_train = X[i-200:i]
    y_train = y[i-200:i]
    X_test = X[i:i+1]
    y_test = y[i:i+1]

    ### Train four kinds of SVM model
    C = 1  # SVM regularization parameter
    svc = svm.SVC(cache_size = 1000, kernel='linear', C=C).fit(X_train, y_train)
    rbf_svc = svm.SVC(cache_size = 1000, kernel='rbf', gamma=0.7, C=C).fit(X_train, y_train)
    poly_svc = svm.SVC(cache_size = 1000, kernel='poly', degree=3, C=C).fit(X_train, y_train)
    lin_svc = svm.LinearSVC(loss='squared_hinge', penalty='l1', dual=False, C=C).fit(X_train, y_train)
    Y_result = y_test


    ### Make the prediction
    for i, clf in enumerate((svc, lin_svc, rbf_svc, poly_svc)):
        pred = clf.predict(X_test)
        Y_result = np.vstack((Y_result, np.array(pred))) # append prediction on Y_result
    return Y_result.T
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号