Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 47 additions & 32 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,56 @@ python:
- 3.6
- 3.7
- 3.8
- "3.10"
- "3.11"
env:
- SKLEARNVERSION=0.23.2
- SKLEARNVERSION=0.24
matrix:
include:
- name: "Python 3.7 on Windows sk-learn v0.23"
os: windows # Windows 10.0.17134 N/A Build 17134
language: shell
before_install:
- choco install python --version 3.7
- python -m pip install --upgrade pip
- pip install nose
env:
- PATH=/c/Python37:/c/Python37/Scripts:$PATH
- SKLEARNVERSION=0.23.2
- name: "Python 3.7 on Windows sk-learn v0.24"
os: windows # Windows 10.0.17134 N/A Build 17134
language: shell
before_install:
- choco install python --version 3.7
- python -m pip install --upgrade pip
- pip install nose
env:
- PATH=/c/Python37:/c/Python37/Scripts:$PATH
- SKLEARNVERSION=0.24
- name: "Python 3.8 on Windows sk-learn v0.24"
os: windows # Windows 10.0.17134 N/A Build 17134
language: shell
before_install:
- choco install python --version 3.8
- python -m pip install --upgrade pip
- pip install nose
env:
- PATH=/c/Python38:/c/Python38/Scripts:$PATH
- SKLEARNVERSION=0.24
- SKLEARNVERSION=0.24.1
- SKLEARNVERSION=0.24.2
- SKLEARNVERSION=1.0
- SKLEARNVERSION=1.0.1
- SKLEARNVERSION=1.0.2
- SKLEARNVERSION=1.1.0
- SKLEARNVERSION=1.1.1
- SKLEARNVERSION=1.1.2
- SKLEARNVERSION=1.1.3
- SKLEARNVERSION=1.2.0
- SKLEARNVERSION=1.2.1
- SKLEARNVERSION=1.2.2
- SKLEARNVERSION=1.3.0
#matrix:
# include:
# - name: "Python 3.7 on Windows sk-learn v0.23"
# os: windows # Windows 10.0.17134 N/A Build 17134
# language: shell
# before_install:
# - choco install python --version 3.7
# - python -m pip install --upgrade pip
# - pip install nose
# env:
# - PATH=/c/Python37:/c/Python37/Scripts:$PATH
# - SKLEARNVERSION=0.23.2
# - name: "Python 3.7 on Windows sk-learn v0.24"
# os: windows # Windows 10.0.17134 N/A Build 17134
# language: shell
# before_install:
# - choco install python --version 3.7
# - python -m pip install --upgrade pip
# - pip install nose
# env:
# - PATH=/c/Python37:/c/Python37/Scripts:$PATH
# - SKLEARNVERSION=0.24
# - name: "Python 3.8 on Windows sk-learn v0.24"
# os: windows # Windows 10.0.17134 N/A Build 17134
# language: shell
# before_install:
# - choco install python --version 3.8
# - python -m pip install --upgrade pip
# - pip install nose
# env:
# - PATH=/c/Python38:/c/Python38/Scripts:$PATH
# - SKLEARNVERSION=0.24
before_install:
- pip3 install cpp-coveralls
install:
Expand Down
7 changes: 5 additions & 2 deletions dame_flame/data_cleaning.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,14 @@ def check_parameters(adaptive_weights, df_holdout, df_input, alpha, FLAME,

# make sure that adaptive_weights is a valid value.
if (adaptive_weights not in ["ridge", "decisiontree", "ridgeCV", "decisiontreeCV"]):
raise Exception("Invalid input error. The acceptable values for "\
# Check to see if adaptive_weights is an object of type scikit-model
if not (hasattr(adaptive_weights, 'fit') and hasattr(adaptive_weights, 'predict')):
raise Exception("Invalid input error. The acceptable values for "\
"the adaptive_weights parameter are 'ridge', "\
"'decisiontree', 'decisiontreeCV', or 'ridgeCV'. Additionally, "\
"adaptive-weights may be 'False' along "\
"with a weight array")
"with a weight array or may be a scikit learn object if it has"\
" a fit, predict method.")


# make sure the two dfs have the same number of columns first:
Expand Down
25 changes: 13 additions & 12 deletions dame_flame/flame_dame_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,21 @@ def find_pe_for_covar_set(df_holdout, treatment_column_name,
clf = Ridge(alpha=alpha_given)
elif adaptive_weights in ["decisiontree", "decisiontreeCV"]:
clf = DecisionTreeRegressor()
else:
elif adaptive_weights == 0:
return False
else:
clf = adaptive_weights
# return False

if adaptive_weights in ["ridge", "decisiontree"]:

if adaptive_weights in ["ridgeCV", "decisiontreeCV"]:
# calculate MSE via cross validation.
mse_treated = -1*np.mean(cross_val_score(clf, x_treated, y_treated,
scoring='neg_mean_squared_error',
cv=5))
mse_control = -1*np.mean(cross_val_score(clf, x_control, y_control,
scoring='neg_mean_squared_error',
cv=5))
else:
# Calculate treated MSE
clf.fit(x_treated, y_treated)
predicted = clf.predict(x_treated)
Expand All @@ -111,15 +121,6 @@ def find_pe_for_covar_set(df_holdout, treatment_column_name,
predicted = clf.predict(x_control)
mse_control = mean_squared_error(y_control, predicted)

else:
# calculate MSE via cross validation.
mse_treated = -1*np.mean(cross_val_score(clf, x_treated, y_treated,
scoring='neg_mean_squared_error',
cv=5))
mse_control = -1*np.mean(cross_val_score(clf, x_control, y_control,
scoring='neg_mean_squared_error',
cv=5))

pe_array.append(mse_treated + mse_control)

return np.mean(pe_array)
Expand Down
5 changes: 4 additions & 1 deletion dame_flame/matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# License: MIT

import numpy as np
import pandas as pd
from . import data_cleaning
from . import dame_algorithm
from . import flame_algorithm
Expand Down Expand Up @@ -242,7 +243,9 @@ def predict(self, input_data, pre_dame=float('inf'), C=0.1):

# the first few items all look the same, then the last item is from dame
self.df_units_and_covars_matched = return_array[0]
self.df_units_and_covars_matched = self.df_units_and_covars_matched.append(return_array[-1][0], sort=True)
# self.df_units_and_covars_matched = self.df_units_and_covars_matched.append(return_array[-1][0], sort=True)
self.df_units_and_covars_matched = pd.concat([self.df_units_and_covars_matched, return_array[-1][0]])

if self.repeats == True:
# we have to aggregate the indexes appearing more than once,
# those are the ones which were matched units in both dame and flame:
Expand Down