Skip to content

Commit

Permalink
update to deal with the case when wrong hyper-parameters are given fo…
Browse files Browse the repository at this point in the history
…r learning curve
  • Loading branch information
HyunjunA committed Dec 6, 2022
1 parent 3632c99 commit 394f099
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions machine/learn/skl_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,8 @@ def plot_imp_score(tmpdir, _id, coefs, feature_names, imp_score_type):

def plot_learning_curve(tmpdir,_id,model,features,target,cv,return_times=True):


# Plot learning curve
print("Plotting learning curve...")


features = np.array(features)
Expand Down Expand Up @@ -1147,14 +1148,15 @@ def plot_learning_curve(tmpdir,_id,model,features,target,cv,return_times=True):
# test_scores_std = np.std(test_scores, axis=1)

# if train_sizes.tolist() has nan, then replace it with 0
# check if train_sizes.tolist has nan
if np.isnan(train_sizes.tolist()).any():
# check if all of train_sizes.tolist has nan

if np.isnan(train_sizes.tolist()).all():
#replace nan with -1
train_sizes = np.nan_to_num(train_sizes, nan=-1)
if np.isnan(train_scores.tolist()).any():
if np.isnan(train_scores.tolist()).all():
# replace nan with -1
train_scores = np.nan_to_num(train_scores, nan=-1)
if np.isnan(test_scores.tolist()).any():
if np.isnan(test_scores.tolist()).all():
# replace nan with -1
test_scores = np.nan_to_num(test_scores, nan=-1)

Expand All @@ -1174,6 +1176,8 @@ def plot_learning_curve(tmpdir,_id,model,features,target,cv,return_times=True):


def plot_pca_2d(tmpdir,_id,features,target):

print("plot_pca_2d")
# import numpy as np
# import matplotlib.pyplot as plt

Expand Down Expand Up @@ -1475,6 +1479,8 @@ def plot_tsne(tmpdir,_id,features,target):
# print(X)
# print(y)

print("Plotting t-SNE")

tsne = TSNE(n_components=2, verbose=1, random_state=123)
X_2d = tsne.fit_transform(X)

Expand Down Expand Up @@ -1510,7 +1516,12 @@ def plot_tsne(tmpdir,_id,features,target):
# path = tmpdir + _id + '/tsneJson_' + _id + '.json'
# import json

# X_2d
print("X_2d",X_2d)
print("y",y)

X_2d = [1]
y = [1]

# save X and y to json file
tsne_dict = {
Expand Down

0 comments on commit 394f099

Please sign in to comment.