(注:此部分与数据处理算法有大量重叠)
云模型
Logistic回归
主成分分析
支持向量机(SVM)
K-均值(K-Means)
近邻法
朴素Bayes判别法
决策树方法
人工神经网络(BP、RBF、Hopfield、SOM)
正则化方法
kernel算法
(单目标决策:不确定型决策、风险决策、效用函数、决策树、灵敏度分析) (多目标决策:分层序列法、多目标线性规划、层次分析法)
# 求导
from __future__ import print_function
from __future__ import division
import numpy as np
import scipy as sp
import scipy.misc
def f(x):
return 2*x*x + 3*x + 1
print(sp.misc.derivative(f, 2))
11.0
# 马鞍面
from __future__ import print_function
from __future__ import division
import numpy as np
import scipy as sp
import matplotlib.pylab as plt
from pylab import *
from mpl_toolkits.mplot3d import Axes3D
fig = figure()
ax = Axes3D(fig)
X = np.linspace(-10, 10, 30)
Y = np.linspace(-10, 10, 30)
X, Y = np.meshgrid(X, Y)
Z = (X*X)/3 - (Y*Y)/3
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap="hot")
show()
# 求不定积分
from __future__ import print_function
from __future__ import division
import numpy as np
import scipy as sp
import scipy.integrate
f = lambda x : x**2
print(sp.integrate.quad(f, 0, 2))
print(sp.integrate.fixed_quad(f, 0, 2))
(2.666666666666667, 2.960594732333751e-14) (2.6666666666666661, None)
# 求解非线性方程组
from __future__ import print_function
from __future__ import division
import numpy as np
import scipy as sp
import scipy.optimize
def f(x):
return [5*x[1] + 3, 4*x[0]*x[0], x[1]*x[2] - 1.5]
ans = sp.optimize.fsolve(f, [0, 0, 0])
print(ans)
print(f(ans))
[ 0. -0.6 -2.5] [0.0, 0.0, 0.0]
# 求解线性方程组
from __future__ import print_function
from __future__ import division
import numpy as np
import scipy as sp
import matplotlib.pylab as plt
import scipy.linalg
a = np.array([[1, 3, 5], [2, 5, 1], [2, 3, 8]])
b = np.array([10, 8, 3])
print(sp.linalg.solve(a, b))
# print(sp.linalg.inv(a).dot(b))
[-9.28 5.16 0.76]
# 画三叶玫瑰线
from __future__ import print_function
from __future__ import division
import numpy as np
import scipy as sp
import matplotlib.pylab as plt
t = np.linspace(0, 2*np.pi, 1000, endpoint=True)
p = 3 * np.sin(3 * t)
plt.subplot(111, polar=True)
plt.plot(t, p, lw=3, color="g")
plt.grid(True)
plt.show()
# 画星形线
from __future__ import print_function
from __future__ import division
import numpy as np
import scipy as sp
import matplotlib.pylab as plt
t = np.linspace(-10, 10, 1024)
X = np.cos(t) ** 3
Y = np.sin(t) ** 3
plt.plot(X, Y, label="My", lw=3, color="g")
plt.xlim(X.min()*1.2, X.max()*1.2)
plt.ylim(Y.min()*1.2, Y.max()*1.2)
plt.grid(True)
plt.legend()
plt.show()
# 画随机散点图
from __future__ import print_function
from __future__ import division
import numpy as np
import scipy as sp
import numpy.random
import matplotlib.pylab as plt
X = np.random.rand(50)
Y = np.random.rand(50)
colors = np.random.rand(50)
area = np.pi * (15 * np.random.rand(50)) ** 2
plt.scatter(X, Y, s=area, c=colors)
plt.show()
import numpy as np
import pylab as pl
import time
from matplotlib import cm
def iter_point(c):
z = c
for i in range(1, 100): # 最多迭代100次
if abs(z)>2: break # 半径大于2则认为逃逸
z = z*z+c
return i # 返回迭代次数
def draw_mandelbrot(cx, cy, d):
"""
绘制点(cx, cy)附近正负d的范围的Mandelbrot
"""
x0, x1, y0, y1 = cx-d, cx+d, cy-d, cy+d
y, x = np.ogrid[y0:y1:200j, x0:x1:200j]
c = x + y*1j
start = time.clock()
mandelbrot = np.frompyfunc(iter_point,1,1)(c).astype(np.float)
print("time=",time.clock() - start)
pl.imshow(mandelbrot, cmap=cm.Blues_r, extent=[x0,x1,y0,y1])
pl.gca().set_axis_off()
x,y = 0.27322626, 0.595153338
pl.subplot(231)
draw_mandelbrot(-0.5,0,1.5)
for i in range(2,7):
pl.subplot(230+i)
draw_mandelbrot(x, y, 0.2**(i-1))
pl.subplots_adjust(0.02, 0, 0.98, 1, 0.02, 0)
pl.show()
time= 0.21249099999999999 time= 0.4001999999999999 time= 0.46425299999999936 time= 0.5263220000000004 time= 0.7834560000000002 time= 0.908315