擅长:python、mysql、java
<p>我只是自己实现的,因为在scikit learn中似乎没有这样的东西:</p>
<pre><code>class MultiModelRegressor(RegressorMixin):
def __init__(self,models):
self.models = models
def fit(self, X, y):
X_ = X.copy().reshape(X.shape[1], X.shape[0])
y_ = y.copy().reshape(-1, y.shape[0])
for features, labels, model in [(a,b,c) for a in X_ for b in y_ for c in self.models]:
if not model == None:
model.fit(features.reshape(-1,1), labels.reshape(-1,1))
def predict(self, X):
X_ = X.copy().reshape(X.shape[1], X.shape[0])
prediction = np.empty(X.shape[0])
for features, model in [(a,b) for a in X_ for b in self.models]:
if not model == None:
prediction = (np.array([a+b for a in prediction for b in model.predict(features.reshape(-1,1))] ) / 2)
return prediction.reshape(X.shape[0])
</code></pre>
<p>它并不完美,但我真的不明白为什么像这样的东西还没有在scikit学习,我的意思是它相当有用,不是吗?你知道吗</p>