If you run the fit attribute on an instance of a sklearn estimator, for example LinearRegression(), is the result stored somewhere inside the instance of the class? I don't create a new object but I fit the model and can do new things like predict etc.
lr = LinearRegression()
lr.fit(X_train, y_train)
Could I achieve something similar with a class of my own. How could I store the result from run_model() inside the instance of the class?
data = pd.DataFrame({'n':[1,1,4,1],
'target':[36,8,0,41],
'string':['z', 's', 'd', 'h']})
class test:
def __init__(self,
dataframe,
target,
features):
self.dataframe=dataframe
self.target = target
self.features = features
def x_y(self):
X=self.dataframe[self.features]
y=self.dataframe[[self.target]]
return X, y
def run_model(self):
X, y = self.x_y()
list_result = X.n*4
return list_result
a = test(dataframe=data, target='target', features=['n','string'])
a.run_model()
Output:
0 4
1 4
2 16
3 4
Name: n, dtype: int64