GithubHelp home page GithubHelp logo

py-test-knn's Introduction

Python KNN: 从头开始创建一个 Python 包

项目初始化

  • poetry init 初始化项目结构

  • poetry source add --default mirrors https://mirrors.bfsu.edu.cn/pypi/web/simple/ 添加国内源

  • poetry add [lib name] 添加依赖

  • poetry add [lib name] --group test 添加测试环境依赖

  • poetry run python 运行当前项目环境下的 python

  • poetry run pytest 运行单元测试

Python 包需要:

  • 同名文件夹 ty_kmeans: packages = [{include = "ty_kmeans"}]
  • 文件夹下必须要有 __init__.py (可以为空)
    • __init__.py 中可以有 __all__ = [...] 来指定用户可以获取的符号(变量、函数、模块)

安装本项目

  • 安装:pip install git+https://github.com/peacemo/py-test-knn.git

  • 使用

from tyknn import knn
from sklearn.model_selection import train_test_split
from sklearn.datasets import load_iris
from sklearn.metrics import confusion_matrix

iris = load_iris()
X = iris.data
Y = iris.target

X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.33, random_state=42)

K = 5
y_pred = knn(X_train, y_train, X_test, K)

confusion_matrix(y_test, y_pred)

>>> output
array([[19,  0,  0],
       [ 0, 15,  0],
       [ 0,  1, 15]])

py-test-knn's People

Contributors

peacemo avatar

Stargazers

 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.