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

https://study.163.com/course/introduction.htm?courseId=1005269003&utm_campaign=commission&utm_source=cp-400000000398149&utm_medium=share

机器学习,统计分项目联系: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)

 https://study.163.com/provider/400000000398149/index.htm?share=2&shareId=400000000398149( 欢迎关注博主主页,学习python视频资源,还有大量免费python经典文章)

python蒙特卡洛脚本模拟—挑战者号爆炸概率的更多相关文章

  1. python蒙特卡洛算法模拟赌博模型

    sklearn实战-乳腺癌细胞数据挖掘 https://study.163.com/course/introduction.htm?courseId=1005269003&utm_campai ...

  2. Python爬虫-百度模拟登录(二)

    上一篇-Python爬虫-百度模拟登录(一) 接上一篇的继续 参数 codestring codestring jxG9506c1811b44e2fd0220153643013f7e6b1898075 ...

  3. [其他] 蒙特卡洛(Monte Carlo)模拟手把手教基于EXCEL与Crystal Ball的蒙特卡洛成本模拟过程实例:

    http://www.cqt8.com/soft/html/723.html下载,官网下载 (转帖)1.定义: 蒙特卡洛(Monte Carlo)模拟是一种通过设定随机过程,反复生成时间序列,计算参数 ...

  4. Python使用mechanize模拟浏览器

    Python使用mechanize模拟浏览器 之前我使用自带的urllib2模拟浏览器去进行訪问网页等操作,非常多站点都会出错误,还会返回乱码.之后使用了 mechanize模拟浏览器,这些情况都没出 ...

  5. 测试开发Python培训:模拟登录新浪微博-技术篇

    测试开发Python培训:模拟登录新浪微博-技术篇   一般一个初学者项目的起点就是登陆功能的自动化,而面临的项目不同实现的技术难度是不一样的,poptest在做测试开发培训中更加关注技术难点,掌握技 ...

  6. Python爬虫之模拟登录微信wechat

    不知何时,微信已经成为我们不可缺少的一部分了,我们的社交圈.关注的新闻或是公众号.还有个人信息或是隐私都被绑定在了一起.既然它这么重要,如果我们可以利用爬虫模拟登录,是不是就意味着我们可以获取这些信息 ...

  7. Python实现网站模拟登陆

    一.实验简介 1.1 基本介绍 本实验中我们将通过分析登陆流程并使用 Python 实现模拟登陆到一个实验提供的网站,在实验过程中将学习并实践 Python 的网络编程,Python 实现模拟登陆的方 ...

  8. 利用Python中的mock库对Python代码进行模拟测试

    这篇文章主要介绍了利用Python中的mock库对Python代码进行模拟测试,mock库自从Python3.3依赖成为了Python的内置库,本文也等于介绍了该库的用法,需要的朋友可以参考下     ...

  9. Jenkins 为Jenkins添加Windows Slave远程执行python项目脚本

    为Jenkins添加Windows Slave远程执行python项目脚本   by:授客 QQ:1033553122 测试环境 JAVA JDK 1.7.0_13 (jdk-7u13-windows ...

随机推荐

  1. drop与truncate与delete的区别与联系

    在mysql和oracle数据库中delete与truncate都是可以用来对数据进行删除操作,但是二者又有些不同. 主要有以下几个区别: 区别一: 根据sql语言分类来说,delete属于DML语言 ...

  2. java复习(1)

    这几天开学,很多知识点还很生疏,这两天先把java基础复习一下,有段时间没有写博客了,今天就先谈谈进制转换吧. 1.二进制数的原码,补码和反码 1):对于正数的原码,补码和反码均是相同的,这里不讨论了 ...

  3. SpringBoot项目中遇到的BUG

    1.启动项目的时候报错 1.Error starting ApplicationContext. To display the auto-configuration report re-run you ...

  4. MySQL数据库数据类型以及INT(M)的含义

    nt(M)我们先来拆分,int是代表整型数据那么中间的M应该是代表多少位了,后来查mysql手册也得知了我的理解是正确的,下面我来举例说明.   MySQL 数据类型中的 integer types ...

  5. 2019.9.17更换ubuntu的镜像源 ubuntu安装lamp iis安装网站和ftp站

    更换ubuntu的镜像源 /etc/apt/sources.list cp  /etc/apt/sources.list  /etc/apt/sources.list.bak 备份这个文件 vim / ...

  6. Big Data(四)关于Hadoop的HA&CAP理论详解

    问题 思路: 主从集群:结构相对简单,主与从协作 主:单点,数据一致好掌握 问题: 单点故障,集群整体不可用 压力过大,内存受限 解决方案 单点故障: 高可用方案:HA(High Available) ...

  7. (转) Delete/Truncate删除,释放表空间、降低高水位线、resize释放磁盘空间相关优化

    硬盘空间不足,打算删除数据库中的多余数据,但删除数据后,硬盘硬盘空间不能释放.[delete后用:alter table table_name move    truncate后用:alter tab ...

  8. 《SaltStack技术入门与实践》—— 实践案例 <中小型Web架构>3 Memcached配置管理

    实践案例 <中小型Web架构>3 Memcached配置管理 本章节参考<SaltStack技术入门与实践>,感谢该书作者: 刘继伟.沈灿.赵舜东 Memcached介绍 Me ...

  9. 【NOIP2016提高A组五校联考4】square

    题目 分析 首先,设\(f_{i,j}\)表示最大的以(i,j)为左下角的正方形的边长. 转移显然,\(f_{i,j}=\max(f_{i-1,j},f_{i,j-1},f_{i-1,j-1})+1\ ...

  10. shell练习--PAT题目1008:数组元素循环右移问题 (失败案例,运行超时)

    一个数组A中存有N(>)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(≥)个位置,即将A中的数据由(A​0​​A​1​​⋯A​N−1​​)变换为(A​N−M​​⋯A​N−1​​A ...