![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
MachineLearning(Python版)
以实战案例带大家入门机器学习。希望大家多多指正!本栏采用Python语言编写。
Home丶Basic
这个作者很懒,什么都没留下…
展开
-
多项式拟合
import matplotlib.pyplot as pltimport numpy as npn_dots = 20x = np.linspace(0,1,n_dots)# print(x,end=" ")y = np.sqrt(x) + 0.2*np.random.rand(n_dots) - 0.1# print(y,end=" ")# 画出拟合多项式def plot_polynomial_fit(x,y,order): p = np.poly1d(np.polyfit原创 2020-06-14 21:44:35 · 697 阅读 · 0 评论 -
蒙特卡罗方法求圆周率
import matplotlib.pyplot as pltimport numpy as npn_dots = 10000x = np.random.random(n_dots)y = np.random.random(n_dots)distance = np.sqrt(x ** 2 + y ** 2)in_circle = distance[distance < 1]pi = 4 * float(len(in_circle)) / n_dotsprint(pi)3.149原创 2020-06-06 17:01:02 · 190 阅读 · 0 评论 -
多项式简单拟合
import matplotlib.pyplot as pltimport numpy as np# 预生成20个噪声点,拟采用5次多项式拟合参数,计6个多项式参数n_dots = 20n_order = 5x = np.linspace(0, 1, n_dots)y = np.sqrt(x) + 0.2*np.random.rand(n_dots)p = np.poly1d(np.polyfit(x, y, n_order))# 打印各多项式参数print(p.coeffs)t原创 2020-06-06 16:56:18 · 226 阅读 · 0 评论 -
随机漫步算法(全局最优化求解)
import matplotlib.pyplot as pltimport numpy as npn_person = 2000n_times = 500t = np.arange(n_times)steps = 2 * np.random.randint(2, size=(n_person, n_times)) - 1amount = np.cumsum(steps, axis=1)sd_amount = amount ** 2mean_sd_amount = sd_amount.m原创 2020-06-06 16:37:56 · 722 阅读 · 0 评论 -
埃氏筛法生成质数序列
import matplotlib.pyplot as pltimport numpy as np# np.arange()函数返回一个有终点和起点的固定步长的排列,如[1,2,3,4,5],起点是1,终点是100,默认步长为1a = np.arange(1, 101)# 埃拉托斯特尼筛法,必须把不大于根号n的所有素数的倍数剔除,剩下的就是素数。n_max = int(np.sqrt(len(a)))is_prime = np.ones(len(a), dtype=bool)is_prime原创 2020-06-06 16:26:24 · 142 阅读 · 0 评论 -
Matplotlib绘制正弦曲线
import numpy as npimport matplotlib.pyplot as plt# 在 [0, 4*PI] 之间取 100 个点x = np.linspace(0, 4 * np.pi, num=50)# 计算这 50个点的正弦值,并保存在变量 yy = np.sin(x)# 画出 x, y 即是我们的正弦曲线plt.plot(x, y)...原创 2020-06-06 16:23:21 · 1065 阅读 · 0 评论