Skip to content Skip to sidebar Skip to footer

Creating A Custom Estimator: State Mean Estimator

I've trying to develop a very simple initial model to predict the amount of fines a nursing home might expect to pay based on its location. This is my class definition #initial mo

Solution 1:

The problem I am seeing is in your fit method, iteritems basically iterates over columns rather than rows. you should use itertuples which will give you row wise data. just change the loop in your fit method to

for row in pd.DataFrame(state_mean_series).itertuples(): #row format is [STATE, mean_value]
    self.group_averages[row[0]] = row[1]

and then in your predict method, just do a fail safe check by doing

prediction = dictionary.get(row.STATE, None) # None is the default value here in case the 'AS' doesn't exist. you may replace it with what ever you want

Post a Comment for "Creating A Custom Estimator: State Mean Estimator"