当前位置: 首页>>代码示例>>Python>>正文


Python Utility.normalize_data方法代码示例

本文整理汇总了Python中utility.Utility.normalize_data方法的典型用法代码示例。如果您正苦于以下问题:Python Utility.normalize_data方法的具体用法?Python Utility.normalize_data怎么用?Python Utility.normalize_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在utility.Utility的用法示例。


在下文中一共展示了Utility.normalize_data方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: plot_selected

# 需要导入模块: from utility import Utility [as 别名]
# 或者: from utility.Utility import normalize_data [as 别名]
 def plot_selected(self, df, columns, start_index, end_index):
     """Plot the desired columns over index values in the given range."""
     util = Utility()
     df = util.normalize_data(df)
     self.plot_data(df.ix[start_index:end_index, columns], "Bitcoin")
开发者ID:harindersingh,项目名称:MachineLearningUsingPython,代码行数:7,代码来源:dataplotting.py

示例2: test_run

# 需要导入模块: from utility import Utility [as 别名]
# 或者: from utility.Utility import normalize_data [as 别名]
def test_run():
    '''function to test all the utlities'''
    # Define a date range
    dates = pd.date_range('2015-04-02', '2016-04-01')

    # Choose feature symbols to read
    location = os.path.join(base_dir, "BitcoinData")
    symbols = os.listdir(location)

    #build dataframe consisting of all features
    dfreader = DataReader()
    util = Utility()
    location = os.path.join(base_dir, "BitcoinData")
    df = dfreader.get_data(location, symbols, dates)
    df = util.normalize_data(df)

    for index in range(len(symbols)):
        symbols[index] = symbols[index].strip('.csv')

    plotter = DataPlotting()
    #plot dataframe in selected range and given features list
    plotter.plot_selected(df, symbols, '2015-05-01', '2015-06-01')
    #plot dataframe for all given data
    plotter.plot_data(df, "Bitcoin")

    dates = pd.date_range('2010-01-01', '2016-01-01')
    btc_file = "bitcoin-market-price.csv"
    location = os.path.join(base_dir, btc_file)
    df_btc = dfreader.get_btc(location, btc_file, dates)

    stats = Statistics(df)
    rmean = stats.get_rolling_mean(df_btc['bitcoin-market-price'], window=20)
    rstd = stats.get_rolling_std(df_btc.ix[:, 'bitcoin-market-price'], window=20)
    upper_band, lower_band = stats.get_bollinger_bands(rmean, rstd)

    # Plot raw values, rolling mean and Bollinger Bands
    ax = df_btc['bitcoin-market-price'].plot(title="Bollinger Bands", \
                                            label='bitcoin-market-price')
    rmean.plot(label='Rolling mean', ax=ax)
    upper_band.plot(label='upper band', ax=ax)
    lower_band.plot(label='lower band', ax=ax)

    # Add axis labels and legend
    ax.set_xlabel("Date")
    ax.set_ylabel("Price")
    ax.legend(loc='upper left')
    plt.show()

    #compute daily returns
    daily_returns = stats.compute_daily_returns(df_btc)
    plotter.plot_data(daily_returns, title="Daily returns", ylabel="Daily returns")

    daily_returns.replace(to_replace=np.inf, value=np.NaN, inplace=True)
    # Plot a histogram
    daily_returns.hist(bins=21)

    # Get mean as standard deviation
    mean = daily_returns.mean()
    std = daily_returns.std()

    #print type(mean)
    plt.axvline(mean[0], color='w', linestyle='dashed', linewidth=2)
    plt.axvline(std[0], color='r', linestyle='dashed', linewidth=2)
    plt.axvline(-std[0], color='r', linestyle='dashed', linewidth=2)
    plt.show()

    # Scatterplots
    df.plot(kind='scatter', x='hash_rate', y='market_cap')
    beta_XOM, alpha_XOM = np.polyfit(df['hash_rate'], df['market_cap'], 1)  # fit poly degree 1
    plt.plot(df['hash_rate'], beta_XOM*df['market_cap'] + alpha_XOM, '-', color='r')
    plt.show()

    # Calculate correlation coefficient
    correlation = df['avg_block_size'].corr(df['n_tx'], method='pearson')
    print correlation
开发者ID:harindersingh,项目名称:MachineLearningUsingPython,代码行数:77,代码来源:dataextract.py


注:本文中的utility.Utility.normalize_data方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。