使用pytorch 拟合出一条简单直线。
准备数据 xy.csv.
https://github.com/xiangkejun/machine_learning_xx/blob/master/tf2_xx/xy.csv
准备 line_gress.py
#encoding=utf-8
# 拟合出一条直线
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
# from matplotlib.font_manager import FontProperties
import torch
print(torch.__version__) # 1.2
# my_font = FontProperties(fname=r"c:\windows\fonts\simsun.ttc",size=16)
# data = pd.read_csv("F:/AI/python_xx/xy.csv",sep=',')
data = pd.read_csv("xy.csv",sep=',')
x = data.x
y = data.y
tx = torch.FloatTensor(x).reshape(20,1)
ty = torch.FloatTensor(y).reshape(20,1)
print(x)
print(y)
# data