Skip to content

Commit

Permalink
do not load model if save is false
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarouc committed Jul 17, 2017
1 parent 6f6b037 commit e40bd46
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions polyssifier/polyssifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def fit_clf(args, clf_name, val, n_fold, project_name, save, scoring):
file_name = 'poly_{}/models/{}_{}.p'.format(
project_name, clf_name, n_fold + 1)
start = time.time()
if os.path.isfile(file_name):
if save and os.path.isfile(file_name):
logger.info('Loading {} {}'.format(file_name, n_fold))
clf = joblib.load(file_name)
else:
Expand Down Expand Up @@ -296,22 +296,25 @@ def create_polynomial(data, degree):
:return: a new data matrix of the specified degree (for polynomial fitting purposes)
'''

#First we make an empty matrix which is the size of what we wish to pass through to linear regress
# First we make an empty matrix which is the size of what we wish to pass through to linear regress
height_of_pass_through = data.shape[0]
width_of_pass_through = degree * data.shape[1]
to_pass_through = np.zeros(shape=(height_of_pass_through, width_of_pass_through))
to_pass_through = np.zeros(
shape=(height_of_pass_through, width_of_pass_through))

#These are the width and height of each "exponeneted" matrix
# These are the width and height of each "exponeneted" matrix
height_exponential_matrix = data.shape[0]
width_exponential_matrix = data.shape[1]

for i in range(degree):
to_add_in = data ** (i + 1)
for j in range(height_exponential_matrix):
for k in range(width_exponential_matrix):
to_pass_through.itemset((j, k + i * width_exponential_matrix), (to_add_in.item(j, k)))
to_pass_through.itemset(
(j, k + i * width_exponential_matrix), (to_add_in.item(j, k)))
return to_pass_through


def polyr(data, label, n_folds=10, scale=True, exclude=[],
feature_selection=False, num_degrees=1, save=False, scoring='r2',
project_name='', concurrency=1, verbose=True):
Expand All @@ -337,9 +340,9 @@ def polyr(data, label, n_folds=10, scale=True, exclude=[],
'''
if num_degrees != 1:
polynomial_data = create_polynomial(data, num_degrees)
return polyr(data = polynomial_data, label = label, n_folds=n_folds, scale=scale, exclude=exclude,
feature_selection=feature_selection, num_degrees=1, save=save, scoring=scoring,
project_name=project_name, concurrency=concurrency, verbose=verbose)
return polyr(data=polynomial_data, label=label, n_folds=n_folds, scale=scale, exclude=exclude,
feature_selection=feature_selection, num_degrees=1, save=save, scoring=scoring,
project_name=project_name, concurrency=concurrency, verbose=verbose)

assert label.shape[0] == data.shape[0],\
"Label dimesions do not match data number of rows"
Expand Down

0 comments on commit e40bd46

Please sign in to comment.