在训练SVM回归时,通常建议在训练之前缩放输入要素.
但是如何扩展目标呢?通常这不是必要的,我认为没有必要为什么这么做.
但是,在scikit-learn示例中,SVM回归来自:http: //scikit-learn.org/stable/auto_examples/svm/plot_svm_regression.html
通过在训练之前引入线y = y/1000,预测将分解为恒定值.在训练之前缩放目标变量可以解决问题,但我不明白为什么有必要.
是什么导致这个问题?
import numpy as np
from sklearn.svm import SVR
import matplotlib.pyplot as plt
# Generate sample data
X = np.sort(5 * np.random.rand(40, 1), axis=0)
y = np.sin(X).ravel()
# Add noise to targets
y[::5] += 3 * (0.5 - np.random.rand(8))
# Added line: this will make the prediction break down
y=y/1000
# Fit regression model
svr_rbf = SVR(kernel='rbf', C=1e3, gamma=0.1)
svr_lin = SVR(kernel='linear', C=1e3)
svr_poly = SVR(kernel='poly', C=1e3, degree=2)
y_rbf = svr_rbf.fit(X, …Run Code Online (Sandbox Code Playgroud) 我只是想了解在使用Python C API时如何处理引用计数.
我想用C++调用Python函数,如下所示:
PyObject* script;
PyObject* scriptRun;
PyObject* scriptResult;
// import module
script = PyImport_ImportModule("pythonScript");
// get function objects
scriptRun = PyObject_GetAttrString(script, "run");
// call function without/empty arguments
scriptResult = PyObject_CallFunctionObjArgs(scriptRun, NULL);
if (scriptResult == NULL)
cout << "scriptResult = null" << endl;
else
cout << "scriptResult != null" << endl;
cout << "print reference count: " << scriptResult->ob_refcnt << endl;
Run Code Online (Sandbox Code Playgroud)
pythonScript.py中的Python代码非常简单:
def run():
return 1
Run Code Online (Sandbox Code Playgroud)
"PyObject_CallFunctionObjArgs"的文档说您获得了一个新的引用作为返回值.所以我希望"scriptResult"的引用计数为1.但是输出是:
scriptResult != null
print reference count: 72
Run Code Online (Sandbox Code Playgroud)
此外,如果我在循环中执行此操作而不减少引用计数,我会期望内存泄漏.然而,这似乎不会发生.
有人可以帮我理解吗?
亲切的问候!