Giter Site home page Giter Site logo

ml_algorithms's Introduction

TSP and KNN Algorithms

This repository contains implementations of the Travelling Salesman Problem (TSP) algorithm and the K-Nearest Neighbors (KNN) algorithm in Python.

TSP_algorithm.py

This script provides a solution to the Travelling Salesman Problem using a brute-force approach to find the shortest possible route that visits each city and returns to the origin city.

Features

  • Calculate the total distance for a given path.
  • Find the shortest path by examining all permutations of city visits.

Usage

  1. Define the list of cities.
  2. Define the distance matrix representing distances between each pair of cities.
  3. Run the script to find and print the shortest path and its distance.

KNN_algorithm.py

This script implements the K-Nearest Neighbors algorithm for classification. It predicts the class of a given test sample based on the majority class among its k nearest neighbors in the training dataset.

Features

  • Initialize the KNN model with a specified k value.
  • Fit the model with training data.
  • Predict the class labels for test data.

Usage

  1. Define the training data (X_train) and corresponding labels (y_train).
  2. Define the test data (X_test).
  3. Initialize the KNN model and fit it with the training data.
  4. Predict the labels for the test data and print the predictions.

Example

import numpy as np
from knn_algorithm import KNN

X_train = np.array([[1, 2], [2, 3], [3, 4], [4, 5]])
y_train = np.array([0, 0, 1, 1])
X_test = np.array([[2.5, 3.5]])

model = KNN(k=3)
model.fit(X_train, y_train)
predictions = model.predict(X_test)
print("Predictions:", predictions)

ml_algorithms's People

Contributors

rumeysacelik avatar

Stargazers

 avatar Hüsrev AKBAŞ avatar Bilgehan Zeki ÖZAYTAÇ 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.