zoukankan      html  css  js  c++  java
  • Day 15:一些数据分析、机器学习和深度学习包和框架&&入门案例

    NumPy

    简单介绍一下数值计算库numpy, 主要用来存储和计算矩阵。https://numpy.org/

    主要功能包括:

    1. N 维数组对象 Array(最基本的数据结构)
    2. 成熟的广播机制
    3. 能够解决线性代数、随机数生成数相关问题
    import numpy as np
    import numpy.linalg as lg #求逆

    #了解线性代数例程
    # Import required modules/ libraries
    import numpy as np
    from scipy import linalg
     
    # We are trying to solve a linear algebra system which can be given as:
    #               1x + 2y =5
    #               3x + 4y =6
    # Create input array
    A= np.array([[1,2],[3,4]])
     
    # Solution Array
    B= np.array([[5],[6]])
     
    # Solve the linear algebra
    X= linalg.solve(A,B)
    print(X)
     
    # Checking Results
    print("
     Checking results, following vector should be all zeros")
    print(A.dot(X)-B)
    
    output:
    [[-4. ]
     [ 4.5]]
    
     Checking results, following vector should be all zeros
    [[0.]
     [0.]]

    SciPy

     基于 Python,也是用于数学计算的工具包。https://www.scipy.org/

    import scipy
    import numpy
    #多项式
    from numpy import poly1d
    myPolynomial = poly1d([1,2,3])
    print(myPolynomial)
    
    print("
    Squaring the polynomial: 
    ")
    print(myPolynomial* myPolynomial)
    
    print("
    Integrating the polynomial: 
    ")
    print(myPolynomial.integ(k=3))
    
    print("
    Finding derivative of the polynomial: 
    ")
    print(myPolynomial.deriv())
    
    print("
    Solving the polynomial for 2: 
    ")
    print(myPolynomial(2))
    
    output:
       2
    1 x + 2 x + 3
    
    Squaring the polynomial: 
    
       4     3      2
    1 x + 4 x + 10 x + 12 x + 9
    
    Integrating the polynomial: 
    
            3     2
    0.3333 x + 1 x + 3 x + 3
    
    Finding derivative of the polynomial: 
    
     
    2 x + 2
    
    Solving the polynomial for 2: 
    
    11
    View Code
    #科学傅立叶变换 (SciPy Fourier Transforms)
    # Import Fast Fourier Transformation requirements
    from scipy.fftpack import fft
    import numpy as np
     
    # Number of sample points
    N = 600
     
    # sample spacing
    T = 1.0 / 800.0
    x = np.linspace(0.0, N*T, N)
    y = np.sin(50.0 * 2.0*np.pi*x) + 0.5*np.sin(80.0 * 2.0*np.pi*x)
    yf = fft(y)
    xf = np.linspace(0.0, 1.0/(2.0*T), N//2)
     
    # matplotlib for plotting purposes
    import matplotlib.pyplot as plt
    plt.plot(xf, 2.0/N * np.abs(yf[0:N//2]))
    plt.grid()
    plt.show()

     使用Matplotlib绘制图表。

       SciPy的特殊子软件包定义了许多数学物理学的功能。 可用功能包括通风,贝塞尔,贝塔,椭圆,伽马,超几何,开尔文,马修,抛物柱面,球面波和曲面。

      让我们看一下贝塞尔函数例子。

    # Import special package
    from scipy import special
    import numpy as np
    def drumhead_height(n, k, distance, angle, t):
        kth_zero = special.jn_zeros(n, k)[-1]
        return np.cos(t) * np.cos(n*angle) * special.jn(n, distance*kth_zero)
    theta = np.r_[0:2*np.pi:50j]
    radius = np.r_[0:1:50j]
    x = np.array([r * np.cos(theta) for r in radius])
    y = np.array([r * np.sin(theta) for r in radius])
    z = np.array([drumhead_height(1, 1, r, theta, 0.5) for r in radius])
     
    # Plot the results for visualization
    import matplotlib.pyplot as plt
    from mpl_toolkits.mplot3d import Axes3D
    from matplotlib import cm
    fig = plt.figure()
    ax = Axes3D(fig)
    ax.plot_surface(x, y, z, rstride=1, cstride=1, cmap=cm.jet)
    ax.set_xlabel('X')
    ax.set_ylabel('Y')
    ax.set_zlabel('Z')
    plt.show()

    Pandas

    Pandas 是 Python 中,功能强大的数据分析库。提供关于数据分析高级的数据结构,各种各样的分析工具,确保整个数据处理的过程更加容易。https://pandas.pydata.org/

    Matplotlib

    python 中非常强大的 2D 绘图工具。提供方便易用的绘图接口,能使用在 Python 脚本,IPython shell、Jupyter Notebook、Web 应用服务器等。https://matplotlib.org/

    Seaborn

    Seaborn 是一个基于 Matplotlib 的 Python 数据可视化库,提供绘制更加高层和优美的图形接口。http://seaborn.pydata.org/

    scikit-learn

    scikit-learn 是适用于数据处理和机器学习处理非常强大的库。提供数据降维、回归、聚类、分类等功能,是机器学习从业者的必备库之一。https://scikit-learn.org/

    TensorFlow

    TensorFlow 由 Google 与 Brain Team 合作开发,是一个采用数据流图(data flow graphs),用于数值计算的开源软件库。http://www.tensorfly.cn/

    PyTorch

    PyTorch 是使用 GPU 和 CPU 优化的深度学习张量库,也是深度学习的重要的一个库。

    https://pytorch.org/

  • 相关阅读:
    linux系统更新及开启自动更新
    关于ICO的一些理解
    中小学教育缴费遇到的一些问题
    中小学教育缴费----支付宝回传数据.net core 接收中文乱码
    中小学教育缴费——验签失败
    C# MVC+EF—WebApi
    C# MVC+EF—页面搭建
    C# MVC+EF—结构搭建
    EF中的预先加载和延迟加载
    WebApi路由
  • 原文地址:https://www.cnblogs.com/PiaYie/p/14968973.html
Copyright © 2011-2022 走看看