Skip to content

Commit

Permalink
Resolve vulnerabilities (#23)
Browse files Browse the repository at this point in the history
* update vulnerabilities

* resulv additional vuln

* remove for later verisons of pandas
  • Loading branch information
ssharpe42 authored Apr 4, 2023
1 parent 4530a2d commit 882932a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
34 changes: 19 additions & 15 deletions ablation/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,19 @@ def stratified_subsample(self, percentage, random_state=42):
def add_random_features(self, n_rand_features=4, random_state=42):

np.random.seed(random_state)
random_train = np.random.normal(0, 1, (len(self.X_train), n_rand_features))
random_test = np.random.normal(0, 1, (len(self.X_test), n_rand_features))
random_train = np.random.normal(
0, 1, (len(self.X_train), n_rand_features)
)
random_test = np.random.normal(
0, 1, (len(self.X_test), n_rand_features)
)
self.X_train = np.concatenate([self.X_train, random_train], -1)
self.X_test = np.concatenate([self.X_test, random_test], -1)

# Calculate the random feature names
random_feature_names = [f"#RANDOM{idx}#" for idx in range(n_rand_features)]
random_feature_names = [
f"#RANDOM{idx}#" for idx in range(n_rand_features)
]

# Add random feature names to list of post-encoded features
self.feature_names += random_feature_names
Expand Down Expand Up @@ -96,7 +102,11 @@ def agg_map(self):
@property
def random_feat_idx(self):
return np.array(
[idx for (idx, val) in enumerate(self.feature_names) if "#RANDOM" in val]
[
idx
for (idx, val) in enumerate(self.feature_names)
if "#RANDOM" in val
]
)

@property
Expand Down Expand Up @@ -295,12 +305,9 @@ def prepare_har_data() -> NumpyDataset:

# Load Columns
feature_names = pd.read_table(
path.join(DATA_PATH, "har_features.txt"),
sep="\s+",
header=None,
squeeze=True,
path.join(DATA_PATH, "har_features.txt"), sep="\s+", header=None
)
feature_names = feature_names[1].values
feature_names = feature_names.iloc[:, 1].values

# Standard Scaler
scaler = StandardScaler().fit(x_train)
Expand Down Expand Up @@ -335,12 +342,9 @@ def split_dataset(

assert test_perc > 0, "Must have a test set"

(
X_train,
X_test,
y_train,
y_test,
) = train_test_split(X, y, test_size=test_perc, random_state=42)
(X_train, X_test, y_train, y_test,) = train_test_split(
X, y, test_size=test_perc, random_state=42
)

if val_perc > 0:
(X_train, X_val, y_train, y_val,) = train_test_split(
Expand Down
6 changes: 4 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ seaborn
pandas
scikit-learn>=1.1.0
captum
pytorch_lightning>=1.6.5
torch
torch>=1.13.1, < 2.0.0
pytorch_lightning>=1.6.5, < 2.0.0
certifi>=2022.12.07
werkzeug >= 2.2.3

0 comments on commit 882932a

Please sign in to comment.