Skip to content
Open
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,8 @@ dmypy.json

# Pyre type checker
.pyre/
Project02/.idea/inspectionProfiles/profiles_settings.xml
Project02/.idea/inspectionProfiles/Project_Default.xml
Project02/.idea/misc.xml
*.iml
*.xml
3 changes: 3 additions & 0 deletions Project02/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Project02/source/Evaluation/CrossValidation.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def validate(
stratify: bool = False,
model_params=[],
predict_params=[],
train_params=None,
) -> float:
"""Perform cross-validation using k=num_folds folds

Expand Down Expand Up @@ -209,6 +210,9 @@ def validate(
# Instantiate the model
self.algorithm = model(training_data, self.target_feature, *model_params)

# Train the model
if train_params is not None:
self.algorithm.train(*train_params)
fold_results = self.calculate_results_for_fold(self.algorithm, test_data, predict_params=predict_params)

overall_results.append(fold_results)
Expand Down
5 changes: 3 additions & 2 deletions Project02/source/Utilities/Preprocess.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import math

from typing import List, Callable
import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
import pandas as pd

Converter = dict[str, Callable]
Bins = dict[str, int]
Converter = Dict[str, Callable]
Bins = Dict[str, int]


class Preprocessor:
Expand Down
14 changes: 8 additions & 6 deletions Project02/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def demonstrate_clustering(k):

# Perform one iteration of clustering
kmeans._initialize_clusters()
kmeans._update_samples(False)
kmeans._update_samples()

# Print clusters
for index, cluster in enumerate(kmeans.clusters):
Expand Down Expand Up @@ -313,13 +313,14 @@ def demonstrate_average_classification_performance():

# # Perform 10-fold CV for E-NN
print("\nRunning on E-NN")
# Define hyper-parameters
# # Define hyper-parameters
num_neighbors = 5

eknn_cv = CrossValidation(training_data, target_feature="class")
eknn_results = eknn_cv.validate(EditedKNN, 10, True, predict_params=[num_neighbors, False, 0.0])

# Convert the results to performance metrics
eknn_cv = CrossValidation(training_data.copy(), target_feature="class")
eknn_results = eknn_cv.validate(EditedKNN, 10, True, predict_params=[num_neighbors, False, 0.0], train_params=[num_neighbors])

# # Convert the results to performance metrics
eknn_measures = ExperimentHelper.convert_classification_results_to_measures(
eknn_results, classification_levels
)
Expand All @@ -335,7 +336,7 @@ def demonstrate_average_classification_performance():
num_neighbors = 5
num_clusters = 5

kmeans_cv = CrossValidation(training_data, target_feature="class")
kmeans_cv = CrossValidation(training_data.copy(), target_feature="class")
kmeans_results = kmeans_cv.validate(
KNN, 10, True, model_params=[False, None, num_clusters], predict_params=[num_neighbors]
)
Expand Down Expand Up @@ -457,6 +458,7 @@ def project_demonstration():
demonstrate_average_classification_performance()
input("")


# Display average performance across ten folds for k-NN, k-Means, and ENN on a regression data set
demonstrate_average_regression_performance()

Expand Down