LinearRegression与svm.SVR之间的差异(内核=“线性") [英] difference between LinearRegression and svm.SVR(kernel="linear")
问题描述
首先,此论坛上存在与该论坛非常相似的问题,但请相信我没有匹配的内容,因此请不要重复.
First there are questions on this forum very similar to this one but trust me none matches so no duplicating please.
我遇到了使用scikit的sklearn进行线性回归的两种方法,但我无法理解两者之间的区别,尤其是在第一个代码中调用了train_test_split()方法的情况下,而在另一种直接适合的方法中调用了方法.
I have encountered two methods of linear regression using scikit's sklearn and I am failing to understand the difference between the two, especially where in first code there's a method train_test_split() called while in the other one directly fit method is called.
我正在研究多种资源,而这个问题对我来说很令人困惑.
I am studying with multiple resources and this single issue is very confusing to me.
首先使用SVR
X = np.array(df.drop(['label'], 1))
X = preprocessing.scale(X)
y = np.array(df['label'])
X_train, X_test, y_train, y_test = cross_validation.train_test_split(X, y, test_size=0.2)
clf = svm.SVR(kernel='linear')
clf.fit(X_train, y_train)
confidence = clf.score(X_test, y_test)
第二个是这个
# Split the data into training/testing sets
diabetes_X_train = diabetes_X[:-20]
diabetes_X_test = diabetes_X[-20:]
# Split the targets into training/testing sets
diabetes_y_train = diabetes.target[:-20]
diabetes_y_test = diabetes.target[-20:]
# Create linear regression object
regr = linear_model.LinearRegression()
# Train the model using the training sets
regr.fit(diabetes_X_train, diabetes_y_train)
# Make predictions using the testing set
diabetes_y_pred = regr.predict(diabetes_X_test)
所以我的主要重点是使用svr(kernel ="linear")和使用LinearRegression()之间的区别
So my main focus is the difference between using svr(kernel="linear") and using LinearRegression()
推荐答案
这是我发现的:
直观地讲,作为所有回归变量,它都试图通过最小化成本函数使一条线适合数据.但是,关于SVR的有趣部分是您可以部署非线性内核.在这种情况下,您将结束非线性回归,即拟合曲线而不是直线. 此过程基于内核技巧以及对偶而非原始中解决方案/模型的表示.也就是说,模型表示为训练点的组合,而不是特征和某些权重的函数.同时,基本算法保持不变:非线性过程中唯一真正的变化是核函数,其从简单的内积变为某些非线性函数.
Intuitively, as all regressors it tries to fit a line to data by minimising a cost function. However, the interesting part about SVR is that you can deploy a non-linear kernel. In this case you end making non-linear regression, i.e. fitting a curve rather than a line. This process is based on the kernel trick and the representation of the solution/model in the dual rather than in the primal. That is, the model is represented as combinations of the training points rather than a function of the features and some weights. At the same time the basic algorithm remains the same: the only real change in the process of going non-linear is the kernel function, which changes from a simple inner product to some non linear function.
因此SVR也允许非线性拟合问题,而LinearRegression()仅用于具有直线的简单线性回归(在两种情况下都可以包含任意数量的特征).
So SVR allows non linear fitting problems as well while LinearRegression() is only for simple linear regression with straight line (may contain any number of features in both cases).
这篇关于LinearRegression与svm.SVR之间的差异(内核=“线性")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!