zoukankan      html  css  js  c++  java
  • Python for Data Science

    Chapter 5 - Basic Math and Statistics

    Segment 7 - Transforming dataset distributions

    import numpy as np
    import pandas as pd
    import scipy
    
    import matplotlib.pyplot as plt
    from matplotlib import rcParams
    import seaborn as sb
    
    import sklearn
    from sklearn import preprocessing
    from sklearn.preprocessing import scale
    
    %matplotlib inline
    rcParams['figure.figsize'] = 5, 4
    sb.set_style('whitegrid')
    

    Normalizing and transforming features with MinMaxScalar() and fit_transform()

    address = '~/Data/mtcars.csv'
    
    cars = pd.read_csv(address)
    cars.columns = ['car_names','mpg','cyl','disp', 'hp', 'drat', 'wt', 'qsec', 'vs', 'am', 'gear', 'carb']
    
    mpg = cars.mpg
    plt.plot(mpg)
    
    [<matplotlib.lines.Line2D at 0x7f8460556b70>]
    

    png

    cars[['mpg']].describe()
    
    mpg
    count 32.000000
    mean 20.090625
    std 6.026948
    min 10.400000
    25% 15.425000
    50% 19.200000
    75% 22.800000
    max 33.900000
    mpg_matrix = mpg.values.reshape(-1,1)
    
    scaled = preprocessing.MinMaxScaler()
    
    scaled_mpg = scaled.fit_transform(mpg_matrix)
    plt.plot(scaled_mpg)
    
    [<matplotlib.lines.Line2D at 0x7f845fe54828>]
    

    png

    scaled = preprocessing.MinMaxScaler(feature_range=(0,10))
    
    scaled_mpg = scaled.fit_transform(mpg_matrix)
    plt.plot(scaled_mpg)
    
    [<matplotlib.lines.Line2D at 0x7f845fdb8550>]
    

    png

    Using scale() to scale your features

    standardized_mpg = scale(mpg, axis=0, with_mean=False, with_std=False)
    plt.plot(standardized_mpg)
    
    [<matplotlib.lines.Line2D at 0x7f845fd91be0>]
    

    png

    standardized_mpg = scale(mpg)
    plt.plot(standardized_mpg)
    
    [<matplotlib.lines.Line2D at 0x7f845fcf6470>]
    

    png

  • 相关阅读:
    C++中的乱七八糟问题
    在Win环境下配置java的环境进行开发步骤
    常用软件破解
    关于QT建立项目中遇到的相关问题的处理办法
    QT5.4.0安装以及与VS2010整合安装---64bit操作系统解决方案
    STL容器之一vector
    STL
    三种初步简易的方法求解数值问题 of C++
    Visual Studio 简单使用常识操作
    江城感怀---诗一首
  • 原文地址:https://www.cnblogs.com/keepmoving1113/p/14285856.html
Copyright © 2011-2022 走看看