当前位置:网站首页>吴恩达机器学习之线性回归
吴恩达机器学习之线性回归
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))
##数据再改一下 数据不对
边栏推荐
- Innovus卡住,提示X Error:
- The child and binary tree- open root inversion of polynomials
- Study notes of canal
- Redis principle and usage - installation and distributed configuration
- NTT(快速数论变换)多项式求逆 一千五百字解析
- Cat installation and use
- [MySQL] how to execute an SQL statement (2)
- 2022流动式起重机司机考试题模拟考试题库模拟考试平台操作
- Selection and practice of distributed tracking system
- 李沐d2l(四)---Softmax回归
猜你喜欢
What are CSDN spaces represented by
2022 chemical automation control instrument operation certificate test question simulation test platform operation
NTT(快速数论变换)多项式求逆 一千五百字解析
Redis principle and usage - installation and distributed configuration
李沐d2l(四)---Softmax回归
Original root and NTT 5000 word explanation
ext4文件系统打开了DIR_NLINK特性后,link_count超过65000的后使用link_count=1来表示数量不可知
arc-gis基础操作3
Study notes of canal
堆外内存的使用
随机推荐
838. Heap sorting
Selection and practice of distributed tracking system
异常处理机制二
Error: Cannot find module ‘umi‘ 问题处理
JVM触发minor gc的条件
Elastic APM installation and use
"Could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32"
ZXing简化版,转载
力扣刷题,三数之和
Pat grade a a1013 battle over cities
ONTAP 9文件系统的限制
多项式开根
垂直搜索
Windows通过命令备份数据库到本地
Voice chat app source code - Nath live broadcast system source code
论文笔记: 知识图谱 KGAT (未完暂存)
Two tips for pycharm to open multiple projects
2022 chemical automation control instrument operation certificate test question simulation test platform operation
Matlab 绘制阴影误差图
滑动窗口、双指针、单调队列、单调栈