• Raspberry Pi和Python OpenCV人工神经网络和卷积神经网络演示及其机器学习微型框架


    首先,主要讨论和演示机器学习中使用的基本数据模型及其演示,其次开始的深度学习讨论,然后,探讨 ANN 和 CNN 如何预测结果,例如,当呈现未知图像时,CNN 将尝试将其识别为属于它已被训练识别的类别之一。

    Raspberry Pi机器学习

    机器学习数据模型

    安装OpenCV

    k-最近邻(k-NN)模型

    决策树分类器

    主成分分析(PCA)

    
    import matplotlib.pyplot as plt
    import numpy as np
    import pandas as pd
    import seaborn as sns
    from sklearn import decomposition
    from sklearn.preprocessing import scale
    from sklearn.decomposition import PCA
    from sklearn.preprocessing import StandardScaler
    df = pd.read_csv('iris.csv', header=None, sep=',')
    df.columns=['sepal_length', 'sepal_width', 'petal_length',
    'petal_width', 'class']
    df.dropna(how="all", inplace=True) # Drops empty line at EOF
    # Show the first 5 records
    print(df.head())
    f, ax = plt.subplots(1, 4, figsize=(10,5))
    vis1 = sns.distplot(df['sepal_length'],bins=10, ax= ax[0])
    vis2 = sns.distplot(df['sepal_width'],bins=10, ax=ax[1])
    vis3 = sns.distplot(df['petal_length'],bins=10, ax= ax[2])
    vis4 = sns.distplot(df['petal_width'],bins=10, ax=ax[3])
    plt.show()
    # split data table into data X and class labels y
    X = df.ix[:,0:4].values
    y = df.ix[:,4].values
    # Standardize the data
    X_std = StandardScaler().fit_transform(X)
    # Compute the covariance matrix
    mean_vec = np.mean(X_std, axis=0)
    cov_mat = (X_std -mean_vec).T.dot(X_std - mean_vec) /
    (X_std.shape[0] - 1)
    print('Covariance matrix \n%s' %cov_mat)
    # Compute the Eigenvectors and Eigenvalues
    cov_mat = np.cov(X_std.T)
    eig_vals, eig_vecs = np.linalg.eig(cov_mat)
    print('Eigenvectors \n%s' %eig_vecs)
    print('Eigenvalues \n%s' %eig_vals)
    eig_pairs = [(np.abs(eig_vals[i]), eig_vecs[:,i]) for i in
    range(len(eig_vals))]
    eig_pairs.sort()
    eig_pairs.reverse()
    print('Eigenvalues in descending order:')
    for i in eig_pairs:
     print(i[0])
    # Compute the Eigenvalue ratios
    tot = sum(eig_vals)
    var_exp = [(i / tot)*100 for i in sorted(eig_vals,
    reverse=True)]
    cum_var_exp = np.cumsum(var_exp)
    print('Eigenvalue ratios:%s' %cum_var_exp)
    #Create the W matrix
    matrix_w = np.hstack((eig_pairs[0][1].reshape(4,1),
     eig_pairs[1][1].reshape(4,1)))
    print('Matrix W:\n', matrix_w)
    # Transform the X_std dataset to the sub-space Y
    Y = X_std.dot(matrix_w)
    features = ['sepal_length', 'sepal_width', 'petal_length',
    'petal_width']
    # Create a scatter plot for PC1 vs PC2
    x = df.loc[:,features].values
    x = StandardScaler().fit_transform(x)
    pca = PCA(n_components=2)
    principalComponents = pca.fit_transform(x)
    principalDf = pd.DataFrame(data=principalComponents,
    columns=['principal component 1','principal component 2'])
    finalDf = pd.concat([principalDf, df[['class']]], axis=1)
    fig = plt.figure(figsize=(8,8))
    ax = fig.add_subplot(1,1,1)
    ax.set_xlabel('Principal Component 1', fontsize=15)
    ax.set_ylabel('Principal Component 2', fontsize=15)
    ax.set_title('2 Component PCA', fontsize=20)
    targets = ['setosa', 'versicolor', 'virginica']
    colors = ['r', 'g', 'b']
    for target, color in zip(targets, colors):
     indicesToKeep = finalDf['class'] == target
     ax.scatter(finalDf.loc[indicesToKeep, 'principal component
    1'], finalDf.loc[indicesToKeep, 'principal component 2'],
    c=color, s=50)
    ax.legend(targets)
    ax.grid
    plt.show()
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80

    线性判别分析(LDA)

    支持向量机

    学习向量量化

    装袋和随机森林

    人工神经网络及其演示

    识别手写数字

    使用Keras识别手写字

    卷积神经网络及其演示

    MNIST数据集演示

    使用Raspberry Pi的微型机器学习框架

    参阅 - 亚图跨际

  • 相关阅读:
    java计算机毕业设计基于安卓Android/微信小程序的食堂线上预约点餐系统APP
    【每日一句】名人金句学英语(20221130)
    anroid html5 拍照扫码
    【JavaScript】常用内置对象——数组(Array)对象
    【超详细】手把手教你STM32上报温湿度到腾讯云
    leetCode 150 Evaluate Reverse Polish Notation
    C++中冒号(:)、双冒号(::)的作用
    备战面试每日一题
    一阶惯性滤波器的传递函数与时域实现
    CSS怎么选择除了第一个子元素外的其余同级子元素
  • 原文地址:https://blog.csdn.net/jiyotin/article/details/125474256