使用scikit-learn预测数据向量" x"给予" y"?

时间:2015-03-21 08:36:20

标签: python machine-learning scikit-learn regression

使用Scikit学习,基本思想(例如回归)是预测一些" y"给出一个数据向量" x"在适合模特之后。典型代码看起来像这样(改编自here):

from sklearn.svm import SVR
import numpy as np
n_samples, n_features = 10, 5
np.random.seed(0)
y = np.random.randn(n_samples)
X = np.random.randn(n_samples, n_features)
clf = SVR(C=1.0, epsilon=0.2)
clf.fit(X[:-1], y[:-1]) 
prediction = clf.predict(X[-1])
print 'prediction:', prediction[0]
print 'actual:', y[-1]

我的问题是:是否有可能适合某些模型(可能不是SVR)给出" x"和" y",然后预测" x"给予" y"。换句话说,就像这样:

clf = someCLF()
clf.fit(x[:-1], y[:-1])
prediction = clf.predict(y[-1])
#where predict would return the data vector that could produce y[-1]

2 个答案:

答案 0 :(得分:2)

没有。有许多向量(X)可能导致相同的结果(Y),反之亦然。

如果你需要在开始时预测你用作X的数据,你可能会考虑改变你的X和Y.

答案 1 :(得分:1)

在scikit中不可能,没有。

你问的是x和y的生成或联合模型。如果您拟合这样的模型,则可以对分布p(x,y)或条件分布p(x | y)或p(y | x)中的任一个进行推断。朴素贝叶斯是最受欢迎的生成模型,但你不能用scikit的版本进行上述推断。除了微不足道的问题之外,它还会产生糟糕的估计。在给出其余变量的情况下,拟合好的连接模型要比一个变量的条件模型困难得多。