I'm learning machine learning from this tutorial on Kaggle.
I try to modify the project structure so I create a new .py
file to create a new class. This is the class :
class ModelHelper(object):
def __init__(self, model, seed=0, params=None):
params['random_state'] = seed # TypeError: 'NoneType' object does not support item assignment
self.model = model(**params)
def train(self, x_train, y_train):
self.model.fit(x_train, y_train)
def predict(self, x):
return self.model.predict(x)
def fit(self, x, y):
return self.model.fit(x, y)
def feature_importances(self, x, y):
print(self.model.fit(x, y).feature_importances_)
And this is how i used it :
from helper import ModelHelper
log_reg = ModelHelper(model=LogisticRegression);
This is the full error that I got :
Traceback (most recent call last):
File "F:/backup/PycharmProjects/KaggleTitanic/DataAnalysis.py", line 191, in <module>
log_reg = ModelHelper(model=LogisticRegression);
File "F:\backup\PycharmProjects\KaggleTitanic\ModelHelper.py", line 3, in __init__
params['random_state'] = seed # TypeError: 'NoneType' object does not support item assignment
TypeError: 'NoneType' object does not support item assignment
Probably the error caused by params=None
in my __init__
parameter. What I want is to make this params
field optional (I don’t have to pass it if I don’t want to)