Skip to content

assignment-1 completed#1

Merged
cvasoff merged 1 commit intomainfrom
assignment_one
Dec 5, 2025
Merged

assignment-1 completed#1
cvasoff merged 1 commit intomainfrom
assignment_one

Conversation

@cvasoff
Copy link
Owner

@cvasoff cvasoff commented Nov 23, 2025

What changes are you trying to make? (e.g. adding or removing code, refactoring existing code, adding reports)

Adding text and Python code to answer Assignment-1 KNN classifier questions in a Jupyter notebook.

What did you learn from the changes you have made?

I learned that the prediction variable used in a KNN classifier can have more than two categorical values; that the prediction value can be stored in a separate scalar array; and that the accuracy function used to evaluate the KNN model must differ from the KNN score function we were taught in class.

Was there another approach you were thinking about making? If so, what approach(es) were you thinking of?

No, I referred to Hannah's question and Dmytro's possible solution to understand how to split the train/test split when the predictor variables and the response variable are handled separately to create a series of X, y parameters for modelling. Also searched: https://scikit-learn.org

Were there any challenges? If so, what issue(s) did you face? How did you overcome it?

  1. Initially, encountered difficulty coding the train_test_split function: substituted the "predictors_standardized" object for all the predictor variables.
  2. I spent a lot of time trying to debug "wine_tune_grid.fit(X_train, y_train)". Then I realized I'd used the British spelling of "neighbour" earlier in my code, and once I corrected that mistake, I could run the code (i.e., SKlearn only uses the American spelling).
  3. I also spent a lot of time trying to run knn.score, which wouldn't work because the number of variables in the X_test DataFrame changed when I attempted to add a "predicted" class column to X_test, but I could not sort out how to compare the y_test scaler to the X_test dataframe. I reread the question, noticed that "sklearn.metrics import accuracy_score" was imported from the standard libraries, and looked up the "accuracy_score" function on https://scikit-learn.org. Passed the first sklearn example into Google search, and reviewed the AI Overview. Applied this to my assignment code and obtained an accuracy score.

How were these changes tested?

In Jupyter, I saved my code as I went, and when I ran into a problem, I tested my solution for the reasonableness of the answer and/or printed the resulting array. I frequently restarted and reran the entire code.

A reference to a related issue in your repository (if applicable)

Checklist

  • [x ] I can confirm that my changes are working as intended

Copy link

@anjali-deshpande-hub anjali-deshpande-hub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done!

Just one comment: Instead of hardcoding n_neighbors=7, you can use wine_tune_grid.best_params_['n_neighbors'] to get the best neighbour.

@cvasoff cvasoff merged commit b59e8e1 into main Dec 5, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants