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

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

机器学习,统计项目合作请联系

QQ:231469242

测试脚本

测试数据

T is an array of durations, E is a either boolean or binary array representing whether the “death” was observed (alternatively an individual can be censored).

  1. import lifelines
  2. from lifelines.datasets import load_waltons
  3.  
  4. df = load_waltons() # returns a Pandas DataFrame
  5.  
  6. T = df['T']
  7. E = df['E']
  8.  
  9. from lifelines import KaplanMeierFitter
  10. kmf = KaplanMeierFitter()
  11. kmf.fit(T, event_observed=E) # more succiently, kmf.fit(T,E)
  12.  
  13. kmf.survival_function_
  14. '''
  15. Out[7]:
  16. KM_estimate
  17. timeline
  18. 0.0 1.000000
  19. 6.0 0.993865
  20. 7.0 0.987730
  21. 9.0 0.969210
  22. 13.0 0.950690
  23. 15.0 0.938344
  24. 17.0 0.932170
  25. 19.0 0.913650
  26. 22.0 0.888957
  27. 26.0 0.858090
  28. 29.0 0.827224
  29. 32.0 0.821051
  30. 33.0 0.802531
  31. 36.0 0.790184
  32. 38.0 0.777837
  33. 41.0 0.734624
  34. 43.0 0.728451
  35. 45.0 0.672891
  36. 47.0 0.666661
  37. 48.0 0.616817
  38. 51.0 0.598125
  39.  
  40. '''
  41.  
  42. kmf.median_
  43. '''
  44. Out[8]: 56.0
  45. '''
  46. kmf.plot()

  1. import lifelines
  2. from lifelines.datasets import load_waltons
  3. from lifelines import KaplanMeierFitter
  4. df = load_waltons() # returns a Pandas DataFrame
  5.  
  6. kmf = KaplanMeierFitter()
  7. T = df['T']
  8. E = df['E']
  9. groups = df['group']
  10. ix = (groups == 'miR-137')
  11.  
  12. kmf.fit(T[~ix], E[~ix], label='control')
  13. ax = kmf.plot()
  14.  
  15. kmf.fit(T[ix], E[ix], label='miR-137')
  16. kmf.plot(ax=ax)

  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from lifelines.plotting import plot_lifetimes
  4. from numpy.random import uniform, exponential
  5.  
  6. N = 25
  7. current_time = 10
  8. actual_lifetimes = np.array([[exponential(12), exponential(2)][uniform()<0.5] for i in range(N)])
  9. observed_lifetimes = np.minimum(actual_lifetimes,current_time)
  10. observed= actual_lifetimes < current_time
  11.  
  12. plt.xlim(0,25)
  13. plt.vlines(10,0,30,lw=2, linestyles="--")
  14. plt.xlabel('time')
  15. plt.title('Births and deaths of our population, at $t=10$')
  16. plot_lifetimes(observed_lifetimes, event_observed=observed)
  17. print "Observed lifetimes at time %d:\n"%(current_time), observed_lifetimes

  1. import pandas as pd
  2. import lifelines
  3. from lifelines import KaplanMeierFitter
  4. import matplotlib.pyplot as plt
  5.  
  6. data = lifelines.datasets.load_dd()
  7. kmf = KaplanMeierFitter()
  8.  
  9. T = data["duration"]
  10. C = data["observed"]
  11.  
  12. kmf.fit(T, event_observed=C )
  13. plt.title('Survival function of political regimes')
  14. kmf.survival_function_.plot()
  15. kmf.plot()
  16.  
  17. kmf.median_

  1. import pandas as pd
  2. import lifelines
  3. from lifelines import KaplanMeierFitter
  4. import matplotlib.pyplot as plt
  5.  
  6. data = lifelines.datasets.load_dd()
  7. kmf = KaplanMeierFitter()
  8.  
  9. T = data["duration"]
  10. C = data["observed"]
  11.  
  12. kmf.fit(T, event_observed=C )
  13. plt.title('Survival function of political regimes')
  14. kmf.survival_function_.plot()
  15. kmf.plot()
  16.  
  17. ax = plt.subplot(111)
  18.  
  19. dem = (data["democracy"] == "Democracy")
  20. kmf.fit(T[dem], event_observed=C[dem], label="Democratic Regimes")
  21. kmf.plot(ax=ax, ci_force_lines=True)
  22. kmf.fit(T[~dem], event_observed=C[~dem], label="Non-democratic Regimes")
  23.  
  24. plt.ylim(0,1);
  25. plt.title("Lifespans of different global regimes")
  26. kmf.plot(ax=ax, ci_force_lines=True)

应用于保险业,病人治疗,信用卡诈骗

信用卡拖欠

具体文档

http://lifelines.readthedocs.io/en/latest/

https://wenku.baidu.com/view/577041d3a1c7aa00b52acb2e.html?from=search

https://wenku.baidu.com/view/a5adff8b89eb172ded63b7d6.html?from=search

https://github.com/thomas-haslwanter/statsintro_python/tree/master/ISP/Code_Quantlets/10_SurvivalAnalysis/lifelinesDemo

测试代码

  1. # -*- coding: utf-8 -*-
  2. # Import standard packages
  3. import numpy as np
  4. import matplotlib.pyplot as plt
  5. from numpy.random import uniform, exponential
  6. import os
  7.  
  8. # additional packages
  9. from lifelines.plotting import plot_lifetimes
  10. import sys
  11. sys.path.append(os.path.join('..', '..', 'Utilities'))
  12.  
  13. try:
  14. # Import formatting commands if directory "Utilities" is available
  15. from ISP_mystyle import setFonts
  16.  
  17. except ImportError:
  18. # Ensure correct performance otherwise
  19. def setFonts(*options):
  20. return
  21.  
  22. # Generate some dummy data
  23. np.set_printoptions(precision=2)
  24. N = 20
  25. study_duration = 12
  26.  
  27. # Note: a constant dropout rate is equivalent to an exponential distribution!
  28. actual_subscriptiontimes = np.array([[exponential(18), exponential(3)][uniform()<0.5] for i in range(N)])
  29. observed_subscriptiontimes = np.minimum(actual_subscriptiontimes,study_duration)
  30. observed= actual_subscriptiontimes < study_duration
  31.  
  32. # Show the data
  33. setFonts(18)
  34. plt.xlim(0,24)
  35. plt.vlines(12, 0, 30, lw=2, linestyles="--")
  36. plt.xlabel('time')
  37. plt.title('Subscription Times, at $t=12$ months')
  38. plot_lifetimes(observed_subscriptiontimes, event_observed=observed)
  39.  
  40. print("Observed subscription time at time %d:\n"%(study_duration), observed_subscriptiontimes)

where k > 0 is the shape parameter and > 0 is the scale parameter of the
distribution. (It is one of the rare cases where we use a shape parameter different
from skewness and kurtosis.) Its complementary cumulative distribution function is
a stretched exponential function.
If the quantity x is a “time-to-failure,” theWeibull distribution gives a distribution
for which the failure rate is proportional to a power of time. The shape parameter, k,
is that power plus one, and so this parameter can be interpreted directly as follows:
• Avalueofk < 1 indicates that the failure rate decreases over time. This happens
if there is significant “infant mortality,” or defective items failing early and the
failure rate decreasing over time as the defective items are weeded out of the
population.
• Avalueofk D 1 indicates that the failure rate is constant over time. This might
suggest random external events are causing mortality, or failure.
• Avalueofk > 1 indicates that the failure rate increases with time. This happens
if there is an “aging” process, or parts that are more likely to fail as time goes on.
An example would be products with a built-in weakness that fail soon after the
warranty expires.
In the field of materials science, the shape parameter k of a distribution of
strengths is known as the Weibull modulus.

威布尔分布(Weibull distribution),又称韦伯分布或韦布尔分布,是可靠性分析和寿命检验的理论基础。
威布尔分布:在可靠性工程中被广泛应用,尤其适用于机电类产品的磨损累计失效的分布形式。由于它可以利用概率值很容易地推断出它的分布参数,被广泛应用于各种寿命试验的数据处理。
 
随机变量分布之一。威布尔分布(Ⅲ型 极值分布)记为W(k,a,b)。
 
 瑞典工程师威布尔从30年代开始研究轴承寿命,以后又研究结构强度和疲劳等问题。他采用了“链式”模型来解释结构强度和寿命问题。这个模型假设一个结构
是由若干小元件(设为n个)串联而成,于是可以形象地将结构看成是由n个环构成的一条链条,其强度(或寿命)取决于最薄弱环的强度(或寿命)。单个链的强
度(或寿命)为一随机变量,设各环强度(或寿命)相互独立,分布相同,则求链强度(或寿命)的概率分布就变成求极小值分布问题,由此给出威布尔分布函数。
由于零件或结构的疲劳强度(或寿命)也应取决于其最弱环的强度(或寿命),也应能用威布尔分布描述。
  根据1943年苏联格涅坚科的研究结果,不管随机变量的原始分布如何,它的极小值的渐近分布只能有三种,而威布尔分布就是第Ⅲ种极小值分布。
  由于威布尔分布是根据最弱环节模型或串联模型得到的,能充分反映材料缺陷和应力集中源对材料疲劳寿命的影响,而且具有递增的失效率,所以,将它作为材料或零件的寿命分布模型或给定寿命下的疲劳强度模型是合适的。
 
 威布尔分布有多种形式,包括一参数威布尔分布、二参数威布尔分布、三参数威布尔分布或混合威布尔分布。三参数的威布尔分布由形状、尺度(范围)和位置三
个参数决定。其中形状参数是最重要的参数,决定分布密度曲线的基本形状,尺度参数起放大或缩小曲线的作用,但不影响分布的形状。通过改变形状参数可以表示
不同阶段的失效情况;也可以作为许多其他分布的近似,如,可将形状参数设为合适的值以近似正态、对数正态、指数等分布。
二参数的威布尔分布主要用于滚动轴承的寿命试验以及高应力水平下的材料疲
劳试验,三参数的威布尔分布用于低应力水平的材料及某些零件的寿命试验,一般而言,它具有比对数正态分布更大的适用性。但是,威布尔分布参数的分析法估计
较复杂,区间估计值过长,实践中常采用概率纸估计法,从而降低了参数的估计精度.这是威布尔分布目前存在的主要缺点,也限制了它的应用[1] 
 

历史

编辑

1. 1927年,Fréchet(1927)首先给出这一分布的定义。
2. 1933年,Rosin和Rammler在研究碎末的分布时,第一次应用了韦伯分布(Rosin, P.; Rammler, E. (1933), "The Laws Governing the Fineness of Powdered Coal", Journal of the Institute of Fuel 7: 29 - 36.)。
3. 1951年,瑞典工程师、数学家Waloddi Weibull(1887-1979)详细解释了这一分布,于是,该分布便以他的名字命名为Weibull Distribution。

应用

编辑

2.工业制造
研究生产过程和运输时间关系
4.预测天气
5.可靠性和失效分析
6.雷达系统
对接受到的杂波信号的依分布建模
7.拟合度
无线通信技术中,相对指数衰减频道模型,Weibull衰减模型对衰减频道建模有较好的拟合度
8.量化寿险模型的重复索赔
9.预测技术变革
10.风速
由于曲线形状与现实状况很匹配,被用来描述风速的分布
 
 
 
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

生存分析/Weibull Distribution韦布尔分布的更多相关文章

  1. R生存分析AFT

    γ = 1/scale =1/0.902 α = exp(−(Intercept)γ)=exp(-(7.111)*γ) > library(survival) > myfit=survre ...

  2. 生存分析(survival analysis)

    一.生存分析(survival analysis)的定义 生存分析:对一个或多个非负随机变量进行统计推断,研究生存现象和响应时间数据及其统计规律的一门学科. 生存分析:既考虑结果又考虑生存时间的一种统 ...

  3. SPSS数据分析—生存分析

    生存分析是对生存时间进行统计分析的一种技术,所谓生存时间,就是指从某一时间点起到所关心的事件发生的这段时间.这里的时间不一定就是钟表日历上的时间,也有可能是其他的度量单位,比如长度单位等. 生存时间有 ...

  4. survival analysis 生存分析与R 语言示例 入门篇

    原创博客,未经允许,不得转载. 生存分析,survival analysis,顾名思义是用来研究个体的存活概率与时间的关系.例如研究病人感染了病毒后,多长时间会死亡:工作的机器多长时间会发生崩溃等. ...

  5. Cox回归模型【生存分析】

    参考:<复杂数据统计方法--基于R的应用> 吴喜之 在生存分析中,研究的主要对象是寿命超过某一时间的概率.还可以描述其他一些事情发生的概率,例如产品的失效.出狱犯人第一次犯罪.失业人员第一 ...

  6. 生存分析与R--转载

    生存分析与R 生存分析是将事件的结果和出现这一结果所经历的时间结合起来分析的一类统计分析方法.不仅考虑事件是否出现,而且还考虑事件出现的时间长短,因此这类方法也被称为事件时间分析(time-to-ev ...

  7. R语言学习 - 非参数法生存分析--转载

    生存分析指根据试验或调查得到的数据对生物或人的生存时间进行分析和推断,研究生存时间和结局与众多影响因素间关系及其程度大小的方法,也称生存率分析或存活率分析.常用于肿瘤等疾病的标志物筛选.疗效及预后的考 ...

  8. Spark2 生存分析Survival regression

    在spark.ml中,实现了加速失效时间(AFT)模型,这是一个用于检查数据的参数生存回归模型. 它描述了生存时间对数的模型,因此它通常被称为生存分析的对数线性模型. 不同于为相同目的设计的比例风险模 ...

  9. 生存分析与R

    生存分析与R 2018年05月19日 19:55:06 走在码农路上的医学狗 阅读数:4399更多 个人分类: R语言   版权声明:本文为博主原创文章,未经博主允许不得转载. https://blo ...

随机推荐

  1. sql注入waf绕过简单入门

    0x1  白盒 0x2 黑盒 一.架构层 1.寻找源站==> 2.利用同网段==> 3.利用边界漏洞==> ssrf只是一个例子 二.资源限制 Waf为了保证业务运行,会忽略对大的数 ...

  2. c# ms chart 控件使用方法

    第一个简单的chart: spline// Create new data series and set it's visualattributes       Series series = new ...

  3. presto——java.sql.SQLException: Error executing query与javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?异常问题

    使用presto的时候以mysql为presto的数据源 安装的presto是0.95版本:使用的presto-jdbc是0.202的,这里使用jdbc去访问时候,connection可以链接成功,但 ...

  4. [Ubuntu] sogou中文输入法安装

    I install sogou 中文输入法 successfully, after following below steps: 1. install sogou pingyin by deb pac ...

  5. loadrunner socket协议问题归纳(3)

    摘要:通过实例讲解loadrunner中的socket协议性能测试的一种测试方法,如何不依赖loadrunner既定规则,自行控制收发数据包 关键词:Loadrunner,socket,自行控制,收发 ...

  6. php命名空间学习笔记。

    为什么要用命名空间? 在PHP中,命名空间用来解决在编写类库或应用程序时创建可重用的代码如类或函数时碰到的两类问题: 用户编写的代码 与  PHP内部的类/函数/常量或第三方类/函数/常量之间的名字冲 ...

  7. Factorials 阶乘(思维)

    Description N 的阶乘写作N!表示小于等于N的所有正整数的乘积.阶乘会很快的变大,如13!就必须用32位整数类型来存储,70!即使用浮点数也存不下了.你的任务是 找到阶乘最后面的非零位.举 ...

  8. "感应锁屏"Alpha版使用说明

    “感应锁屏”Alpha版使用说明 一.产品介绍 感应锁屏是锁屏软件的一大创新.相比传统的锁屏软件,“感应锁屏”从可操作性.方便性.功能全面性都有了很大的提升,可以让用户方便快捷的进行锁屏操作. “感应 ...

  9. 细节--服务器mysql空密码

    在部署致服务器的时候 发现mysql密码为空的情况 如果采用 root账户的话 试过很多 比如不写下面这行 <property name="password" value=& ...

  10. C++ Primer Plus学习:第十三章

    第十三章 类继承 继承的基本概念 类继承是指从已有的类派生出新的类.例: 表 0-1 player.h class player { private: string firstname; string ...