资源简介
使用python实现多元线性回归,内容包含数据源及代码实现

代码片段和文件信息
import numpy as np
import random
# m denotes the number of examples here not the number of features
def gradientDescent(x y theta alpha m numIterations):
xTrans = x.transpose()
for i in range(0 numIterations):
hypothesis = np.dot(x theta)
loss = hypothesis - y
# avg cost per example (the 2 in 2*m doesn‘t really matter here.
# But to be consistent with the gradient I include it)
cost = np.sum(loss ** 2) / (2 * m)
print(“Iteration %d | Cost: %f“ % (i cost))
# avg gradient per example
gradient = np.dot(xTrans loss) / m
# update
theta = theta - alpha * gradient
return theta
def genData(numPoints bias variance):
x = np.zeros(shape=(numPoints 2))
y = np.zeros(shape=numPoints)
# basically a straight line
for i in range(0 numPoints):
# bias feature
x[i][0] = 1
x[i][1] = i
# our target variable
y[i] = (i + bias) + random.uniform(0 1) * variance
return x y
# gen 100 points with a bias of 25 and 10 variance as a bit of noise
x y = genData(100 25 10)
m n = np.shape(x)
numIterations= 100000
alpha = 0.0005
theta = np.ones(n)
theta = gradientDescent(x y theta alpha m numIterations)
print(theta)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2015-06-18 14:24 MultipleLinearRegression-master\
目录 0 2015-06-18 14:24 MultipleLinearRegression-master\.ipynb_checkpoints\
文件 575 2015-06-18 14:24 MultipleLinearRegression-master\.ipynb_checkpoints\Unti
文件 558 2015-06-18 14:24 MultipleLinearRegression-master\.ipynb_checkpoints\Unti
文件 1042390 2015-06-18 14:24 MultipleLinearRegression-master\East_Africa.pdf
文件 19227 2015-06-18 14:24 MultipleLinearRegression-master\East_Africa.txt
文件 159147 2015-06-18 14:24 MultipleLinearRegression-master\Multiple Linear Regression.pdf
文件 0 2015-06-18 14:24 MultipleLinearRegression-master\README.md
文件 600 2015-06-18 14:24 MultipleLinearRegression-master\Unti
文件 558 2015-06-18 14:24 MultipleLinearRegression-master\Unti
文件 635483 2015-06-18 14:24 MultipleLinearRegression-master\data-text.csv
文件 299008 2015-06-18 14:24 MultipleLinearRegression-master\education.csv
文件 2699586 2015-06-18 14:24 MultipleLinearRegression-master\education_stuff.csv
文件 1279 2015-06-18 14:24 MultipleLinearRegression-master\gradient_descent.py
文件 261 2015-06-18 14:24 MultipleLinearRegression-master\intro_pandas.py
文件 237 2015-06-18 14:24 MultipleLinearRegression-master\intro_pandas.py~
文件 137415 2015-06-18 14:24 MultipleLinearRegression-master\life_exp.csv
文件 660 2015-06-18 14:24 MultipleLinearRegression-master\linreg.py
文件 214 2015-06-18 14:24 MultipleLinearRegression-master\linreg.py~
文件 8176 2015-06-18 14:24 MultipleLinearRegression-master\new.csv
文件 578 2015-06-18 14:24 MultipleLinearRegression-master\regexing.py
文件 373 2015-06-18 14:24 MultipleLinearRegression-master\regexing.py~
文件 207 2015-06-18 14:24 MultipleLinearRegression-master\testingCorrelation.py
文件 40 2015-06-18 14:24 MultipleLinearRegression-master\testingCorrelation.py~
文件 288 2015-06-18 14:24 MultipleLinearRegression-master\testingHomoskedasticity.py
文件 152 2015-06-18 14:24 MultipleLinearRegression-master\testingHomoskedasticity.py~
文件 224 2015-06-18 14:24 MultipleLinearRegression-master\testingNormality.py
文件 64 2015-06-18 14:24 MultipleLinearRegression-master\testingNormality.py~
文件 8534 2015-06-18 14:24 MultipleLinearRegression-master\trafficking_data.csv
相关资源
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
评论
共有 条评论