当前位置:网站首页>吴恩达机器学习之线性回归
吴恩达机器学习之线性回归
2022-07-26 09:20:00 【Alex Su (*^▽^*)】
主要记录自己的课后实践代码的过程
基于这个
一.简单的练习
输出单位矩阵
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
a = np.eye(5)
print(a)
二.数据的绘制
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
path = 'C:/Users/szuacm/Desktop/机器学习/数据/1.txt'
data = pd.read_csv(path, header= 0, names = ['Population', 'Profit'])
print(data)
data.plot(kind='scatter', x='Population', y='Profit', figsize=(12,8))
plt.show()
三.代码
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
def computecost(x, y, theta):
t = np.power(x * theta.T - y, 2)
return sum(t) / (2 * len(x))
path = 'in.txt'
data = pd.read_csv(path, header = None, names = ['Population', 'Profit'])
data.insert(0, 'Ones', 1)
cols = data.shape[1]
x = data.iloc[:, 0:cols - 1]
y = data.iloc[:, cols - 1:cols]
x = np.matrix(x.values)
y = np.matrix(y.values)
theta = np.matrix([0, 0])
print(x.shape, theta.shape, y.shape)
print(computecost(x, y, theta))
##数据再改一下 数据不对
边栏推荐
- Voice chat app source code - Nath live broadcast system source code
- jvm命令归纳
- 李沐d2l(六)---模型选择
- Introduction to excellent verilog/fpga open source project (30) - brute force MD5
- 省政府召开全省高温天气安全防范工作电视电话会议
- 力扣——二叉树剪枝
- JS - DataTables control on the number of displays per page
- 李沐d2l(五)---多层感知机
- 多项式开根
- What are CSDN spaces represented by
猜你喜欢
随机推荐
209. Subarray with the smallest length
The essence of attack and defense strategy behind the noun of network security
Go intelligent robot alpha dog, alpha dog robot go
解决“NOTE: One or more layouts are missing the layout_width or layout_height attributes.”
语音聊天app源码——钠斯直播系统源码
字节缓冲流&字符流详解
Bloom filter
838. 堆排序
本地缓存
【Mysql】Mysql锁详解(三)
Object 的Wait Notify NotifyAll 源码解析
Force button list question
Advanced mathematics | Takeshi's "classic series" daily question train of thought and summary of error prone points
性格测试系统v1.0
原根与NTT 五千字详解
CF1481C Fence Painting
"No input file specified" problem handling
Datax的学习笔记
Introduction to excellent verilog/fpga open source project (30) - brute force MD5
volatile 靠的是MESI协议解决可见性问题?(上)









