sklearn实战-乳腺癌细胞数据挖掘(博客主亲自录制视频教程)

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

 

 

# -*- coding: utf-8 -*-
'''
python入门/爬虫/人工智能/机器学习/自然语言/数据统计分析视频教程网址
https://pythoner.taobao.com/ https://github.com/thomas-haslwanter/statsintro_python/tree/master/ISP/Code_Quantlets/12_Multivariate/multipleRegression
Multiple Regression
- Shows how to calculate the best fit to a plane in 3D, and how to find the
corresponding statistical parameters.
- Demonstrates how to make a 3d plot.
- Example of multiscatterplot, for visualizing correlations in three- to
six-dimensional datasets.
'''
# Import standard packages
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns # additional packages
import sys
import os
sys.path.append(os.path.join('..', '..', 'Utilities')) try:
# Import formatting commands if directory "Utilities" is available
from ISP_mystyle import showData except ImportError:
# Ensure correct performance otherwise
def showData(*options):
plt.show()
return # additional packages ...
# ... for the 3d plot ...
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm # ... and for the statistic
from statsmodels.formula.api import ols def generateData():
''' Generate and show the data: a plane in 3D '''
#随机产生101个数据,取值范围从(-5到5)
x = np.linspace(-5,5,101)
(X,Y) = np.meshgrid(x,x)
# To get reproducable values, I provide a seed value
np.random.seed(987654321)
#np.random.randn产生随机的正太分布数,np.shape(X)表示X的size(101,101)
#np.random.randn(np.shape(X)[0], np.shape(X)[1])表示产生(101,101)个随机数
Z = -5 + 3*X-0.5*Y+np.random.randn(np.shape(X)[0], np.shape(X)[1]) # 绘图
#Set the color
myCmap = cm.GnBu_r
# If you want a colormap from seaborn use:
#from matplotlib.colors import ListedColormap
#myCmap = ListedColormap(sns.color_palette("Blues", 20)) # Plot the figure
fig = plt.figure()
ax = fig.gca(projection='3d')
surf = ax.plot_surface(X,Y,Z, cmap=myCmap, rstride=2, cstride=2,
linewidth=0, antialiased=False)
ax.view_init(20,-120)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
fig.colorbar(surf, shrink=0.6) outFile = '3dSurface.png'
showData(outFile)
#X.flatten()把多维数据展开,弄成一维数据
return (X.flatten(),Y.flatten(),Z.flatten()) def regressionModel(X,Y,Z):
'''Multilinear regression model, calculating fit, P-values, confidence intervals etc.''' # Convert the data into a Pandas DataFrame
df = pd.DataFrame({'x':X, 'y':Y, 'z':Z}) # --- >>> START stats <<< ---
# Fit the model
model = ols("z ~ x + y", df).fit()
# Print the summary
print((model.summary()))
# --- >>> STOP stats <<< ---
return model._results.params # should be array([-4.99754526, 3.00250049, -0.50514907]) #用numpy的线性回归模型,和上面regressionModel函数计算结果一致
def linearModel(X,Y,Z):
'''Just fit the plane, using the tools from numpy''' # --- >>> START stats <<< ---
M = np.vstack((np.ones(len(X)), X, Y)).T
bestfit = np.linalg.lstsq(M,Z)
# --- >>> STOP stats <<< ---
print(('Best fit plane:', bestfit))
return bestfit if __name__ == '__main__':
(X,Y,Z) = generateData()
regressionModel(X,Y,Z)
linearModel(X,Y,Z)

  

 

 

python风控评分卡建模和风控常识(博客主亲自录制视频教程)

how to calculate the best fit to a plane in 3D, and how to find the corresponding statistical parameters的更多相关文章

  1. (转)Markov Chain Monte Carlo

    Nice R Code Punning code better since 2013 RSS Blog Archives Guides Modules About Markov Chain Monte ...

  2. What is an eigenvector of a covariance matrix?

    What is an eigenvector of a covariance matrix? One of the most intuitive explanations of eigenvector ...

  3. kaggle入门项目:Titanic存亡预测(四)模型拟合

    原kaggle比赛地址:https://www.kaggle.com/c/titanic 原kernel地址:A Data Science Framework: To Achieve 99% Accu ...

  4. Course Machine Learning Note

    Machine Learning Note Introduction Introduction What is Machine Learning? Two definitions of Machine ...

  5. [C2P3] Andrew Ng - Machine Learning

    ##Advice for Applying Machine Learning Applying machine learning in practice is not always straightf ...

  6. AI-IBM-cognitive class --Liner Regression

    Liner Regression import matplotlib.pyplot as plt import pandas as pd import pylab as pl import numpy ...

  7. OpenCASCADE PCurve of Topological Face

    OpenCASCADE PCurve of Topological Face eryar@163.com Abstract. OpenCASCADE provides a class BRepBuil ...

  8. The Model Complexity Myth

    The Model Complexity Myth (or, Yes You Can Fit Models With More Parameters Than Data Points) An oft- ...

  9. 中国澳门sinox很多平台CAD制图、PCB电路板、IC我知道了、HDL硬件描述语言叙述、电路仿真和设计软件,元素分析表

    中国澳门sinox很多平台CAD制图.PCB电路板.IC我知道了.HDL硬件描述语言叙述.电路仿真和设计软件,元素分析表,可打开眼世界. 最近的研究sinox执行windows版protel,powe ...

随机推荐

  1. linux及安全第四周总结

    学习内容:使用库函数API和C代码中嵌入汇编代码两种方式使用同一个系统调用 一.用户态.内核态 权限分级——为了系统本身更稳定,使系统不宜崩溃.(并不是所有程序员缩写的代码都很健壮!!) x86 CP ...

  2. 冲刺Two之站立会议9

    今天我们团队主要针对软件的功能进行了改进.因为它目前可以实现视频通话,语音聊天,文件传输和文字聊天的通信功能,我们想要在它的基础上实现临时局域群聊和群聊视频的功能,目前还没有完全实现.

  3. Maven入门系列(一):Eclipse中使用Maven

    Maven下载和安装 在使用Maven之前首先先要下载Mavne的免安装包,下载地址:http://maven.apache.org/download.cgi 想看源码的可以下载src版本,使用的下载 ...

  4. 使用msysgit上传项目到github

    综合这几个教程,终于提价了项目,总结一下流程. (教程1[github入门教程]:http://jingpin.jikexueyuan.com/article/1037.html) (教程2[常见错误 ...

  5. SQL语句及5.7.2 mysql 用户管理

    一.用户的定义 1.1 用户名+主机域 此处为5.7.2版本的mysql当中password字段已改为authentication_string mysql> select user,host, ...

  6. 转载 linux常用的监控命令工具

    工具 简单介绍top 查看进程活动状态以及一些系统状况vmstat 查看系统状态.硬件和系统信息等iostat 查看CPU 负载,硬盘状况sar 综合工具,查看系统状况mpstat 查看多处理器状况n ...

  7. Angular $cookieStore简单应用

    angular.module('cookieStoreExample', ['ngCookies']) .controller('ExampleController', ['$cookieStore' ...

  8. python matplotlib绘图

    import numpy as np import matplotlib.pyplot as plt from scipy.constants.constants import alpha from ...

  9. js函數

    函數是什麼?函數就是被事件驅動或者調用執行的可重複的代碼塊. 函數聲明: 使用關鍵詞function,關鍵詞function大小敏感. function a{代碼塊} 局部變量: 在函數內部聲明的變量 ...

  10. jenkins--svn+Email自动触发1(作业设置)

    项目名称设置: svn设置: 触发构建设置: 构建加入sonar-scanner代码扫描: 邮件设置: 邮件触发器配置: