当前位置:网站首页>吴恩达机器学习之线性回归
吴恩达机器学习之线性回归
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))
##数据再改一下 数据不对
边栏推荐
- Codeworks DP collection
- Thread Join 和Object wait 的区别
- The Child and Binary Tree-多项式开根求逆
- "Could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32"
- 本地缓存
- Qtcreator reports an error: you need to set an executable in the custom run configuration
- Go intelligent robot alpha dog, alpha dog robot go
- Datax的学习笔记
- OnTap 9 file system limitations
- Error: Cannot find module ‘umi‘ 问题处理
猜你喜欢
![[MySQL] how to execute an SQL statement (2)](/img/7b/53f8756458cc318e2f417b1cc0c3f8.png)
[MySQL] how to execute an SQL statement (2)

【线上死锁分析】由index_merge引发的死锁事件

Advanced mathematics | Takeshi's "classic series" daily question train of thought and summary of error prone points

Paper notes: knowledge map kgat (unfinished temporary storage)

volatile 靠的是MESI协议解决可见性问题?(下)

Stm32+mfrc522 completes IC card number reading, password modification, data reading and writing

ext3文件系统的一个目录下,无法创建子文件夹,但可以创建文件

服务器内存故障预测居然可以这样做!

垂直搜索

Li Mu D2L (VI) -- model selection
随机推荐
"Could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32"
【ARKit、RealityKit】把图片转为3D模型
JS - DataTables control on the number of displays per page
csdn空格用什么表示
Flask project learning (I) -- sayhello
Elastic APM installation and use
Conditions for JVM to trigger minor GC
Local cache
2022 tea artist (intermediate) special operation certificate examination question bank simulated examination platform operation
839. Simulation reactor
Does volatile rely on the MESI protocol to solve the visibility problem? (next)
volatile 靠的是MESI协议解决可见性问题?(上)
李沐d2l(四)---Softmax回归
MySQL strengthen knowledge points
Voice chat app source code - Nath live broadcast system source code
STM32+MFRC522完成IC卡号读取、密码修改、数据读写
Codeworks DP collection
Innovus卡住,提示X Error:
垂直搜索
Paper notes: knowledge map kgat (unfinished temporary storage)