随笔分类 - python
摘要:解题思路 思路显而易见,计算几何求凸包 Orz大佬,这Python代码绝绝子 @z1m 补充 2022/4/23 补充Graham算法 Andrew算法 C++版本 class Solution { public: vector<vector<int>> outerTrees(vector<vect
阅读全文
摘要:如题 目的:在 dev-cpp环境下编程,每次运行执行后,会生成.exe文件,占空间较大,无实际作用,考虑使用脚本语言一次性删除 使用工具: Python import os import re root = os.getcwd() for (dirpath, dirnames, filenames
阅读全文
摘要:利用高斯函数,使得较近的数据点决策作用更大! 代码也比较简洁!Accuracy=0.9466666666666667 注意一下: 其实h=1的选取相当于你的先验知识;或者说多尝试几次 让电脑自己试错,有时候其实方法直接的界定其实没有那么严格啦 1 import numpy as np 2 from
阅读全文
摘要:借鉴了老师的代码,但是没有封装 效果还是挺好的 average accuracy>90% 1 from random import shuffle 2 import numpy as np 3 from collections import Counter 4 5 6 def read(path:
阅读全文
摘要:[K-means Algorithm][3D子图] 由于K-means Algorithm是基于随机点选取的, 所以可能结果较差,甚至RE ! ! ! 1 import numpy as np 2 import random 3 import matplotlib.pyplot as plt 4 f
阅读全文
摘要:这里直接是一个二分类,比较简单 本质上就是把各个事件看成独立的,概率分别计算,概率相乘求出条件概率(后验概率) 然后为了防止概率过小,取log,连乘变为连加,即求和 网页上相关的资料很多,这里就不再赘述了,直接上代码: 推荐视频: https://www.bilibili.com/video/BV1
阅读全文
摘要:1 import numpy as np 2 from sklearn.manifold import TSNE 3 import matplotlib.pyplot as plt 4 from mpl_toolkits.mplot3d import Axes3D 5 6 7 def read(pa
阅读全文
摘要:1 import numpy as np 2 3 4 def update(a: int, b: int, c: int) -> tuple: 5 if a > b and a > c and a > 0: 6 return a, "↖" 7 if b > a and b > c and b > 0
阅读全文
摘要:1 import numpy as np 2 3 4 def update(a: int, b: int, c: int) -> tuple: 5 if a > b and a > c: 6 return a, "↖" 7 if b > a and b > c: 8 return b, "↑" 9
阅读全文
摘要:1 import numpy as np 2 3 4 def LCS(X: str, Y: str) -> tuple: 5 n, m = len(X), len(Y) 6 dp = [[0 for col in range(m + 1)] for row in range(n + 1)] 7 fl
阅读全文
摘要:1 INF = 10000 2 3 4 def getGraph() -> tuple: 5 G = [ 6 #a b c d e 7 [0, 4, 5, 0, 0], # a 8 [0, 0, 0, 8, 0], # b 9 [0, 0, 0, 0, -7], # c 10 [0, 0, 0, 0
阅读全文
摘要:1 def horsepool(S: str, P: str) -> tuple: 2 n, m, M = len(S), len(P), 26 3 shift_table = [m for _ in range(M)] 4 for i in range(m - 1): 5 shift_table[
阅读全文
摘要:1 import numpy as np 2 3 4 def sign(x: float) -> int: 5 if x > 0: 6 return 1 7 elif x < 0: 8 return -1 9 else: 10 return 0 11 12 13 def f(w, x, b) ->
阅读全文
摘要:5折交叉验证,测试10次,取平均值: 1 import random 2 3 4 def read(path: str) -> tuple: 5 with open(path, "r") as f: 6 text = f.readlines() 7 M = [] 8 for row in text:
阅读全文
摘要:Python 信息熵-条件熵计算 1 import csv 2 import numpy as np 3 4 5 def read(path: str) -> tuple: 6 with open(path, 'r') as f: 7 text = csv.reader(f) 8 A = [] 9
阅读全文
摘要:python 统计频率 1 import csv 2 import numpy as np 3 4 5 # the method for parse data into a matrix 6 def input_data_to_matrix(): 7 csv_file = open('binary_
阅读全文
摘要:1 def remove_odd_elements(mylist:list): 2 return [element for element in mylist if(element//2*2==element)] 3 4 # a=[12,15,3,10] 5 # print(remove_odd_e
阅读全文
摘要:1 import math 2 import sys 3 4 def f(dep,fib): 5 if dep==10: 6 print(fib*dep) 7 else: 8 fib=fib*dep 9 f(dep+1,fib) 10 print(fib) 11 12 13 def e(max):
阅读全文

浙公网安备 33010602011771号