Skip to content

Commit

Permalink
Changed loglinear regression into Y = b * X^t.
Browse files Browse the repository at this point in the history
  • Loading branch information
omelyanchikd committed Sep 28, 2016
1 parent 05a898a commit 4df8b92
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ace.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"firm_info_10_10_10.csv", "firm_info_100_100_100.csv", "firm_info_10000_1000_100_10.csv", "firm_info_200000.csv"]

regressions = ['loglinear','bayes', 'linear']
regression_types = ["total", "average"]
regression_types = ["average", "total"]

distribute_subsidies = [True, False]
disturb_results = [True, False]
Expand Down
2 changes: 1 addition & 1 deletion firm.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, i, workers, clf, history, disturb_result, regression):
def step(self, subsidies):
print("Firm step " + str(time.time()))
if self.regression == 'loglinear':
self.sales = self.clf.predict([[self.workers * subsidies]])
self.sales = math.exp(self.clf.predict([[math.log(self.workers * subsidies)]]))
else:
self.sales = self.clf.predict([[self.workers, subsidies]])
if self.disturb_result:
Expand Down
4 changes: 3 additions & 1 deletion mape.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ def mape(y_pred, y_true):
res = 0
for i in range(len(y_true)):
res += abs((y_pred[i] - y_true[i])/y_true[i])
return res[0]/len(y_true) * 100
if isinstance(res, list):
return res[0]/len(y_true) * 100
return res / len(y_true) * 100
6 changes: 4 additions & 2 deletions world.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ def __init__(self, employees, firm_info, history, distribute_subsidies, disturb_
self.clf.fit(self.history[['workers', 'subsidies']], self.history['sales'])
elif regression == 'loglinear':
self.history['product'] = self.history.workers.mul(self.history.subsidies)
self.clf = linear_model.LinearRegression(fit_intercept=False, normalize=False)
self.clf.fit(self.history[['product']], self.history[['sales']])
self.history['log_product'] = self.history['product'].apply(math.log)
self.history['log_sales'] = self.history['sales'].apply(math.log)
self.clf = linear_model.LinearRegression(fit_intercept=True)
self.clf.fit(self.history[['log_product']], self.history[['log_sales']])
self.create_firms(firm_info, self.history, self.clf, employees, disturb_result, disturb_coefficients, regression)
self.employees = employees
self.sales = []
Expand Down

0 comments on commit 4df8b92

Please sign in to comment.