Skip to content

Assignment 1#1

Open
amera6 wants to merge 2 commits intomainfrom
assignment-1
Open

Assignment 1#1
amera6 wants to merge 2 commits intomainfrom
assignment-1

Conversation

@amera6
Copy link
Copy Markdown
Owner

@amera6 amera6 commented Nov 25, 2025

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

I added my code and answers to the appropriate cells in the Assignment_1 jupyter notebook. This included calculated the columns and rows of the wine dataframe, standardizing (centring and scaling) the predictor variables, using 10-fold cross-validation to select the best value for nearest neighbours, and then running a K-Nearest Neighbours algorithm on a test set.

What did you learn from the changes you have made?

I learned how to run KNN in python. I had previous experience doing this in R. I also learned more about SciKit Learn functions such as the accuracy score and splitting training and testing sets by proportions.

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

I was testing out how I should index the columns for the the predictor variables given that it's a larger number (13 predictors) than the example used in the class. I ended up just using the same .iloc[ : , :-1] method that was already given in the code.

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

For some reason, the packages would not be installed through VS Code even when the virtual environment was created as per the SETUP.md instructions. This greatly limited my ability to run and test code straight from the notebook. To overcome this, I uploaded a copy of the assignment notebook to my JupyterHub account (through UofT) and drafted my answers there. I was able to re-run the code with no issues on JupyterHub. Then, I opened the original assignment file in VS Code and copied my answers over.

How were these changes tested?

By re-running the cells after each new line of code.

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

Checklist

  • I can confirm that my changes are working as intended

Copy link
Copy Markdown

@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.

In your PR comments, you mentioned that you couldn't run your code in VSCode because of installation issue. If you are still facing this issue, please message Daniel and he can help you set it up so its easier for you in future modules and assignments.

Some review comments:

  1. Instead of hardcoding the best value of neighbor found. You can do -
best_n_neighbors = wine_tune_grid.best_params_['n_neighbors']
knn = KNeighborsClassifier(n_neighbors=best_n_neighbors)
  1. If you do:

X_train, X_test, y_train, y_test = train_test_split(predictors_standardized, wine_df['class'], test_size=0.25)

you can use X_train and X_test instead of iloc[:, :-1] again and its more readable.

@amera6 amera6 closed this Dec 6, 2025
@amera6 amera6 reopened this Dec 6, 2025
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