# -*- coding: utf-8 -*-
"""
Created on Wed Nov 29 11:16:20 2017
@author: sxl
"""
import numpy as np
import matplotlib.pyplot as plt
# Read dataset
x, y = [], []
for sample in open("F:/Python27/spyder/data01.txt", "r"):
xx, yy = sample.split(",")
x.append(float(xx))
y.append(float(yy))
x, y = np.array(x), np.array(y)
# Perform normalization
x = (x - x.mean()) / x.std()
# Scatter dataset
plt.figure()
plt.scatter(x, y, c="g", s=20)
plt.show()
x0 = np.linspace(-2, 4, 100)
# Get regression model under LSE criterion with degree 'deg'
def get_model(deg):
return lambda input_x=x0: np.polyval(np.polyfit(x, y, deg), input_x)
# Get the cost of regression model above under given x, y
def get_cost(deg, input_x, input_y):
return 0.5 * ((get_model(deg)(input_x) - input_y) ** 2).sum()
# Set degrees
test_set = (1, 4, 10)
for d in test_set:
print(get_cost(d, x, y))
# Visualize results
plt.scatter(x, y, c="g", s=20)
for d in test_set:
plt.plot(x0, get_model(d)(), label="degree = {}".format(d))
plt.xlim(-2, 4)
plt.ylim(1e5, 8e5)
plt.legend()
plt.show()
没有合适的资源?快使用搜索试试~ 我知道了~
python绘制热力图利用python中的matplotlib中的pyplot包绘制二维热力图
共2个文件
py:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 4 下载量 110 浏览量
2023-01-30
20:06:28
上传
评论
收藏 1KB ZIP 举报
温馨提示
python绘制热力图利用python中的matplotlib中的pyplot包绘制二维热力图,反映不同区域的热度分布差异,其中函数可以自定义.zip
资源推荐
资源详情
资源评论
收起资源包目录
python绘制热力图利用python中的matplotlib中的pyplot包绘制二维热力图,反映不同区域的热度分布差异,其中函数可以自定义.zip (2个子文件)
regression.py 1KB
G2
hot.py 370B
共 2 条
- 1
处处清欢
- 粉丝: 149
- 资源: 2471
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页