python机器学习-乳腺癌细胞挖掘(博主亲自录制视频)

机器学习,统计分项目联系:QQ:231469242

数据

https://github.com/thomas-haslwanter/statsintro_python/blob/master/ISP/Code_Quantlets/14_Bayesian/bayesianStats/challenger_data.csv

https://github.com/thomas-haslwanter/statsintro_python/tree/master/ISP/Code_Quantlets/14_Bayesian/bayesianStats

因其右侧固体火箭助推器(SRB)的O型环密封圈失效,毗邻的外部燃料舱在泄漏出的火焰的高温烧灼下结构失效,使高速飞行中的航天飞机在空气阻力的作用下于发射后的第73秒解体

华氏31度等于摄氏-0.5555555555555556,因为温度过低造成挑战者号失事。

天气预报称28日的清晨将会非常寒冷,气温接近华氏31度(摄氏-0.5度),这是允许发射的最低温度。过低的温度让莫顿·塞奥科公司的工程师感到担心,该公司是制造与维护航天飞机SRB部件的承包商。在27日晚间的一次远程会议上,塞奥科公司的工程师和管理层同来自肯尼迪航天中心和马歇尔航天飞行中心的NASA管理层讨论了天气问题。部分工程师,如比较著名的罗杰·博伊斯乔利,再次表达了他们对密封SRB部件接缝处的O型环的担心:即,低温会导致O型环的橡胶材料失去弹性。他们认为,如果O型环的温度低于华氏53度(约摄氏11.7度),将无法保证它能有效密封住接缝。他们也提出,发射前一天夜间的低温,几乎肯定把SRB的温度降到华氏40度的警戒温度以下。但是,莫顿·塞奥科公司的管理层否决了他们的异议,他们认为发射进程能按日程进行。

由于低温,航天飞机旁矗立的定点通信建筑被大量冰雪覆盖。肯尼迪冰雪小组在红外摄像机中发现,右侧SRB部件尾部接缝处的温度仅有华氏8度(摄氏-13度):从液氧舱通风口吹来的极冷空气降低了接缝处的温度,让该处的温度远低于气温,并远低于O

# -*- coding: utf-8 -*-

'''

因其右侧固体火箭助推器(SRB)的O型环密封圈失效,毗邻的外部燃料舱在泄漏出的火焰的高温烧灼下结构失效,使高速飞行中的航天飞机在空气阻力的作用下于发射后的第73秒解体

华氏31度等于摄氏-0.5555555555555556,因为温度过低造成挑战者号失事。

天气预报称28日的清晨将会非常寒冷,气温接近华氏31度(摄氏-0.5度),这是允许发射的最低温度。过低的温度让莫顿·塞奥科公司的工程师感到担心,该公司是制造与维护航天飞机SRB部件的承包商。在27日晚间的一次远程会议上,塞奥科公司的工程师和管理层同来自肯尼迪航天中心和马歇尔航天飞行中心的NASA管理层讨论了天气问题。部分工程师,如比较著名的罗杰·博伊斯乔利,再次表达了他们对密封SRB部件接缝处的O型环的担心:即,低温会导致O型环的橡胶材料失去弹性。他们认为,如果O型环的温度低于华氏53度(约摄氏11.7度),将无法保证它能有效密封住接缝。他们也提出,发射前一天夜间的低温,几乎肯定把SRB的温度降到华氏40度的警戒温度以下。但是,莫顿·塞奥科公司的管理层否决了他们的异议,他们认为发射进程能按日程进行。

由于低温,航天飞机旁矗立的定点通信建筑被大量冰雪覆盖。肯尼迪冰雪小组在红外摄像机中发现,右侧SRB部件尾部接缝处的温度仅有华氏8度(摄氏-13度):从液氧舱通风口吹来的极冷空气降低了接缝处的温度,让该处的温度远低于气温,并远低于O形环的设计承限温度。但这个信息从未传达给决策层。

On the day of the Challenger disaster, the outside temperature was 31 ıF.

The posterior distribution of a defect occurring, given this temperature, almost

guaranteed that the Challenger was going to be subject to defective O-rings

Example of PyMC - The Challenger Disaster

This example uses Bayesian methods to find the mean and the 95% confidence

intervals for the likelihood of an O-ring failure O型密封圈失效 in a space shuttle, as a function

of the ambient temperature周围温度.

Input data are the recorded O-ring performances of the space shuttles before 1986.

'''

# Copyright(c) 2015, Thomas Haslwanter. All rights reserved, under the CC BY-SA 4.0 International License

# Import standard packages

import numpy as np

import matplotlib.pyplot as plt

from scipy import stats

import pandas as pd

import seaborn as sns

import os

# additional packages

import pymc as pm

from scipy.stats.mstats import mquantiles

sns.set_context('poster')

def logistic(x, beta, alpha=0):

'''Logistic Function'''

return 1.0 / (1.0 + np.exp(np.dot(beta, x) + alpha))

def getData():

'''Get and show the O-ring data'''

inFile = 'challenger_data.csv'

challenger_data = np.genfromtxt(inFile, skip_header=1, usecols=[1, 2],

missing_values='NA', delimiter=',')

# drop the NA values

challenger_data = challenger_data[~np.isnan(challenger_data[:, 1])]

temperature = challenger_data[:, 0]

failureData = challenger_data[:, 1] # defect or not?

return (temperature, failureData)

def showAndSave(temperature, failures):

'''Shows the input data, and saves the resulting figure'''

# Plot it, as a function of tempature

plt.figure()

setFonts()

sns.set_style('darkgrid')

np.set_printoptions(precision=3, suppress=True)

plt.scatter(temperature, failures, s=200, color="k", alpha=0.5)

plt.yticks([0, 1])

plt.ylabel("Damage Incident?")

plt.xlabel("Outside Temperature [F]")

plt.title("Defects of the Space Shuttle O-Rings vs temperature")

plt.tight_layout

outFile = 'Challenger_ORings.png'

showData(outFile)

def mcmcSimulations(temperature, failures):

'''Perform the MCMC-simulations'''

# Define the prior distributions for alpha and beta

# 'value' sets the start parameter for the simulation

# The second parameter for the normal distributions is the "precision",

# i.e. the inverse of the standard deviation

np.random.seed(1234)

beta = pm.Normal("beta", 0, 0.001, value=0)

alpha = pm.Normal("alpha", 0, 0.001, value=0)

# Define the model-function for the temperature

@pm.deterministic

def p(t=temperature, alpha=alpha, beta=beta):

return 1.0 / (1. + np.exp(beta * t + alpha))

# connect the probabilities in `p` with our observations through a

# Bernoulli random variable.

observed = pm.Bernoulli("bernoulli_obs", p, value=failures, observed=True)

# Combine the values to a model

model = pm.Model([observed, beta, alpha])

# Perform the simulations

map_ = pm.MAP(model)

map_.fit()

mcmc = pm.MCMC(model)

mcmc.sample(120000, 100000, 2)

# --- Show the resulting posterior distributions ---

alpha_samples = mcmc.trace('alpha')[:, None] # best to make them 1d

beta_samples = mcmc.trace('beta')[:, None]

return(alpha_samples, beta_samples)

def showSimResults(alpha_samples, beta_samples):

'''Show the results of the simulations, and save them to an outFile'''

plt.figure(figsize=(12.5, 6))

sns.set_style('darkgrid')

setFonts(18)

# Histogram of the samples:

plt.subplot(211)

plt.title(r"Posterior distributions of the variables $\alpha, \beta$")

plt.hist(beta_samples, histtype='stepfilled', bins=35, alpha=0.85,

label=r"posterior of $\beta$", color="#7A68A6", normed=True)

plt.legend()

plt.subplot(212)

plt.hist(alpha_samples, histtype='stepfilled', bins=35, alpha=0.85,

label=r"posterior of $\alpha$", color="#A60628", normed=True)

plt.legend()

outFile = 'Challenger_Parameters.png'

showData(outFile)

def calculateProbability(alpha_samples, beta_samples, temperature, failures):

'''Calculate the mean probability, and the CIs'''

# Calculate the probability as a function of time

t = np.linspace(temperature.min() - 5, temperature.max() + 5, 50)[:, None]

p_t = logistic(t.T, beta_samples, alpha_samples)

mean_prob_t = p_t.mean(axis=0)

# --- Calculate CIs ---

# vectorized bottom and top 2.5% quantiles for "confidence interval"

quantiles = mquantiles(p_t, [0.025, 0.975], axis=0)

return (t, mean_prob_t, p_t, quantiles)

def showProbabilities(linearTemperature, temperature, failures, mean_prob_t, p_t, quantiles):

'''Show the posterior probabilities, and save the resulting figures'''

# --- Show the probability curve ----

plt.figure(figsize=(12.5, 4))

setFonts(18)

plt.plot(linearTemperature, mean_prob_t, lw=3, label="Average posterior\n \

probability of defect")

plt.plot(linearTemperature, p_t[0, :], ls="--", label="Realization from posterior")

plt.plot(linearTemperature, p_t[-2, :], ls="--", label="Realization from posterior")

plt.scatter(temperature, failures, color="k", s=50, alpha=0.5)

plt.title("Posterior expected value of probability of defect, plus realizations")

plt.legend(loc="lower left")

plt.ylim(-0.1, 1.1)

plt.xlim(linearTemperature.min(), linearTemperature.max())

plt.ylabel("Probability")

plt.xlabel("Temperature [F]")

outFile = 'Challenger_Probability.png'

showData(outFile)

# --- Draw CIs ---

setFonts()

sns.set_style('darkgrid')

plt.fill_between(linearTemperature[:, 0], *quantiles, alpha=0.7,

color="#7A68A6")

plt.plot(linearTemperature[:, 0], quantiles[0], label="95% CI", color="#7A68A6", alpha=0.7)

plt.plot(linearTemperature, mean_prob_t, lw=1, ls="--", color="k",

label="average posterior \nprobability of defect")

plt.xlim(linearTemperature.min(), linearTemperature.max())

plt.ylim(-0.02, 1.02)

plt.legend(loc="lower left")

plt.scatter(temperature, failures, color="k", s=50, alpha=0.5)

plt.xlabel("Temperature [F]")

plt.ylabel("Posterior Probability Estimate")

outFile = 'Challenger_CIs.png'

showData(outFile)

if __name__=='__main__':

(temperature, failures) = getData()

showAndSave(temperature, failures)

(alpha, beta) = mcmcSimulations(temperature, failures)

showSimResults(alpha, beta)

(linearTemperature, mean_p, p, quantiles) = calculateProbability(alpha, beta, temperature, failures)

showProbabilities(linearTemperature, temperature, failures, mean_p, p, quantiles)

python蒙特卡洛模拟return_python蒙特卡洛脚本模拟—挑战者号爆炸概率相关推荐

  1. python获取当前日期的前一天爆炸_python蒙特卡洛脚本模拟—挑战者号爆炸概率

    python机器学习-乳腺癌细胞挖掘(博主亲自录制视频) 机器学习,统计分项目联系:QQ:231469242 数据 https://github.com/thomas-haslwanter/stats ...

  2. linux 模拟打电话,Ubuntu+Python+UIAutomator写Android自动化测试脚本-模拟拨打电话

    序言 首先介绍一下python和uiautomator 1.UIAutomator是Android官方推出的安卓应用界面自动化测试工具,是最理想的针对APK进行自动化功能回归测试的利器,使用UIAut ...

  3. 历史模拟与蒙特卡洛模拟_在PHP中运行蒙特卡洛模拟

    历史模拟与蒙特卡洛模拟 One of the exciting things in the 1980's was programming simulations to solve complex an ...

  4. 用Python脚本模拟登陆获取地铁一卡通的充值和消费记录

    1. 思路 这几天尝试写了个脚本模拟登陆获取地铁一卡通的充值和消费记录,学习了不少新东西,总结下记录下来.整个流程大概这样,首先模拟登陆一卡通的查询网址,分析如何获取验证码,然后就是下载验证码并识别, ...

  5. python实验原理_Python实现蒙特卡洛算法小实验过程详解

    蒙特卡洛算法思想 蒙特卡洛(Monte Carlo)法是一类随机算法的统称,提出者是大名鼎鼎的数学家冯·诺伊曼,他在20世纪40年代中期用驰名世界的赌城-摩纳哥的蒙特卡洛来命名这种方法. 通俗的解释一 ...

  6. Python量化交易实战-41EasyTrader自动化模拟真实交易

    B站配套视频教程观看 EasyTrader自动化模拟真实交易 来到官方文档的使用部分: https://easytrader.readthedocs.io/zh/master/usage/ 一.用法 ...

  7. Python培训分享:python如何用cookie实现自动模拟登录?

    本期教程Python培训教程为大家带来的是python如何用cookie实现自动模拟登录?据小编的了解,python实现cookie自动登录,目前来说有许多第三方库都可以直接使用,这里以常用的requ ...

  8. python网球比赛模拟_Python-体育竞技模拟

    体育竞技分析的IPO模式: 输入I(input):两个球员的能力值,模拟比赛的次数(其中,运动员的能力值,可以通过发球方赢得本回合的概率来表示,一个能力值为0.8的球员,在他发球时,有80%的可能性赢 ...

  9. python简单体育竞技模拟_python初体验 —— 模拟体育竞技

    python初体验 -->>> 模拟体育竞技 一.排球训练营 1. 简介: 模拟不同的两个队伍进行排球的模拟比赛. 2. 模拟原理: 通过输入各自的能力值(Ⅰ),模拟比赛的进行( P ...

  10. 用到oracle是不是就是cs架构,用Oracle 的2Tier协议录制脚本模拟CS系统测试的案例和注意事项pdf...

    Loadrunner使用Oracle 的2Tier协议录制脚本模拟CS系统 测试的案例和注意事项 联系人:qinwenchuang@http://www.doczj.com/doc/f68c11e8f ...

最新文章

  1. 【luogu3398】 仓鼠找sugar [LCA 倍增]
  2. java数独中数独空格初始化,java高手近解决数独问题,看你是不是高手!
  3. OperationalError: (1044, Access denied for user ''@'localhost' to database 'mydb')
  4. 抽奖 | 送树莓派PICO开发板、机械键盘、声控鼠标
  5. fast group合计 report_FastReport报表设计.doc
  6. 头部电商平台如何在大促时,优雅的赚钱?
  7. java列表展开折叠,jQuery Datatables rowGroup折叠/展开
  8. 20.合并两个有序链表
  9. matlab2014b下载 32位,matlab 2014b 32位
  10. 安装过MongoDB(4版本)重新安装时出现错误Verify that you have sufficient privileges to start system services如何解决
  11. python-css偏移反爬(一)
  12. python实现图像二分类特异度(numpy)
  13. 【echarts】echarts根据奇偶设置柱形图颜色切换
  14. Python如何进行语法检查
  15. 【Java实战小项目】考试系统
  16. 考研数学 第5讲一元微分几何应用
  17. 833计算机专业基础是哪本书,想问一下计算机考研统考中,有计算机专业基础综合408和833,有什么区别呢?比如今年西电就是833。哪里可...
  18. python无限制邮件群发软件_收藏 - 使用Python通过SMTP协议群发/单发邮件方法
  19. 单片机--串口通信---11
  20. ctfshow_pwn03

热门文章

  1. Ubuntu16.04定时执行功能
  2. Windows 10 无法访问共享的解决办法大全
  3. 计算机平均值的快捷键,Excel用快捷键和选项求平均值,且能一次对多行多列批量快速求平均值...
  4. hcia是什么等级的证书_华为hcia是什么等级的证书
  5. python导入文件夹下所有包_python 通过文件夹导入包的操作
  6. 计算机硬件广告语,硬件防毒广告宣传语
  7. 开心农场违规 恐面临关停危险
  8. 【FPGA】如何理解全加器
  9. matlab非线性误差的计算(附代码)
  10. js室内地图开发_支付宝小程序室内地图导航开发-支付宝小程序JS加载esmap地图...