GithubHelp home page GithubHelp logo

hw-2's Introduction

HW-2

Question 1

code was done on Jupyter Notebook

This code is designed to perform a K-Nearest Neighbors (KNN) machine learning algorithm on a set of email data to classify emails as spam or not spam. It splits the process into several steps -data preparation -model training -prediction -evaluation.

Initial Setup and Data Loading

  1. Importing Libraries: The code starts by importing necessary libraries. pandas is used for data manipulation, numpy for numerical computations, Counter from collections is used for counting occurrences of elements, helpful in voting for the most common class in KNN predictions.

  2. Loading Data: Data is loaded from spam_train.csv and spam_test.csv using pandas, This dataset contains features extracted from emails along with a class/label indicating whether an email is spam (1) or not spam (0).

  3. ###Data Preparation

  • The features (X) and labels (y) are separated for both training and test sets.
  • Training features are extracted using spam_train.iloc[:, 0:56] (all rows and the first 56 columns assuming the last column is the label)
  • labels are extracted from the class column.
  1. Model Training (KNN) and Predictions

The core of this code revolves around a manual implementation of the KNN algorithm, which involves:

  1. Defining a training function: simulates model training, but in the context of KNN

  2. predict_knn Function: A crucial part of this code that seems to compute the distance between a test sample and all training samples to find the nearest neighbors but lacks the final step to return the most common label among the k-nearest neighbors. Q1

Screenshot 2024-03-03 at 2 53 53 AM

Q3

Screenshot 2024-03-03 at 4 02 59 PM

hw-2's People

Contributors

pokemaster720 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.