Я хотел бы создать собственную модель регрессии, используя scikit learn. Я борюсь с тем, как вернуть значение из функции предикторов. Вот некоторый код, который я прогрессировал. Я намерен использовать его с cross_val_score, но он показывает ошибку в Temp.
class custom_regressor(BaseEstimator, RegressorMixin):
def __init__(self, intValue=0, stringParam="defaultValue", otherParam=None):
self.intValue = intValue
self.stringParam = stringParam
self.differentParam = otherParam
def fit(self, X, y=None):
return self
def predict(self, X):
A1 = -3.37306
A2 = -0.073254
B1 = -5254.56
B2 = 8.91515
C = 618.225
self.values = []
A = A1 - A2*np.log(X['Pressure']+14.7)
B = B1 - B2*np.log(X['Pressure']+14.7)
RVP = np.exp(A-B/(X['Temp']+C))
values = RVP
#{v: i for i, v in enumerate(np.unique(Y))}
self.values.append(values)
return self.values
Вот ошибка:
KeyError Traceback (последний вызов последний) 18 кадров / usr / local / lib / python3 .6 / dist-packages / pandas / core / indexes / base.py в get_lo c (self, ключ, метод, допуск) 2897 return self._engine.get_lo c (ключ) 2898 кроме KeyError: -> 2899 возвращают self._engine.get_lo c (self._maybe_cast_indexer (key)) 2900
indexer = self.get_indexer ([ключ], метод = метод, допуск = допуск) 2901, если индексатор. ndim> 1 или indexer.size> 1:
pandas / _libs / index.pyx в pandas ._ libs.index.IndexEngine.get_lo c ()
pandas / _libs / index.pyx в pandas ._ libs.index.IndexEngine.get_lo c ()
pandas / _libs / hashtable_class_helper.pxi в pandas ._ libs.hashtable.PyObjectHashTable.get_item ()
1015 * pandas / _libs / hashtable_class_helper.pxi в pandas ._ libs.hashtable.PyObjectHashTable.get_item ()
KeyError: 'Temp'