zoukankan      html  css  js  c++  java
  • python 数据标准化归一化实例

    # 数据的标准化归一化简单例子
    
    from sklearn.preprocessing import StandardScaler
    from sklearn.preprocessing import MinMaxScaler
    from matplotlib import gridspec
    import numpy as np
    import matplotlib.pyplot as plt
    
    cps = np.random.random_integers(0, 100, (100, 2))
    
    ss = StandardScaler()
    std_cps = ss.fit_transform(cps)
    
    gs = gridspec.GridSpec(5, 5)
    fig = plt.figure()
    ax1 = fig.add_subplot(gs[0:2, 1:4])
    ax2 = fig.add_subplot(gs[3:5, 1:4])
    
    ax1.scatter(cps[:, 0], cps[:, 1])
    ax2.scatter(std_cps[:, 0], std_cps[:, 1])
    
    plt.show()
    
    # X: numpy array of shape [n_samples, n_features]Training set.
    data = np.random.uniform(0, 100, 10)[:, np.newaxis]
    ss = StandardScaler()
    std_data = ss.fit_transform(data)
    origin_data = ss.inverse_transform(std_data)
    print('data is ', data)
    print('after standard ', std_data)
    print('after inverse ', origin_data)
    print('after standard mean and std is ', np.mean(std_data), np.std(std_data))
    
    data = np.random.uniform(0, 100, 10)[:, np.newaxis]
    mm = MinMaxScaler()
    mm_data = mm.fit_transform(data)
    origin_data = mm.inverse_transform(mm_data)
    print('data is ', data)
    print('after Min Max ', mm_data)
    print('origin data is ', origin_data)
    
    
    
  • 相关阅读:
    MARTIN FOWLER谈敏捷开发
    精益创业
    DEVOPS基础
    测试驱动开发
    持续集成(CONTINUOUS INTEGRATION)
    极限编程
    回归测试
    敏捷开发十二原则
    敏捷开发宣言
    敏捷开发简史
  • 原文地址:https://www.cnblogs.com/princeness/p/11664902.html
Copyright © 2011-2022 走看看