Skip to content

Commit

Permalink
Merge pull request #4 from jaywyawhare/dev
Browse files Browse the repository at this point in the history
Bug-Fix : Added a fallback mech if pca has NaN
  • Loading branch information
jaywyawhare authored Oct 28, 2023
2 parents cb0fa31 + 1d4c6d0 commit 1a99612
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,22 @@ def eval(X_train, y_train, X_test, y_test, model, eval_metrics):
pass


def pca(X_train, X_test, y_train, y_test, slider):
def featureExtraction(X_train, X_test, slider):
"""
Function to perform PCA and return the top k components.
Args:
X_train: The training data.
X_test: The testing data.
y_train: The training target.
y_test: The testing target.
slider: The number of components to use for PCA.
Returns:
The training and testing data with the top k components.
"""
if X_train.isnan().any():
X_train = X_train.fillna(X_train.mean())
if X_test.isnan().any():
X_test = X_test.fillna(X_test.mean())
scalar = StandardScaler()
X_train = scalar.fit_transform(X_train)
X_test = scalar.transform(X_test)
Expand Down Expand Up @@ -178,7 +180,7 @@ def training(
"""
if slider is not None:
X_train, X_test = pca(X_train, X_test, y_train, y_test, slider)
X_train, X_test = featureExtraction(X_train, X_test, slider)
if model_selection_radio == "Comparative Analysis":
st.header("Comparative Analysis")
comparison_results = {}
Expand Down
2 changes: 2 additions & 0 deletions src/plot_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ def generate_pca_plot(df, target_column):
Returns:
None
"""

df.fillna(0, inplace=True)
scaler = StandardScaler()
df_std = scaler.fit_transform(df)

Expand Down

0 comments on commit 1a99612

Please sign in to comment.