From 69d79f6cd51b9449ba45748e613043df098b4ca7 Mon Sep 17 00:00:00 2001 From: liuy <3454986494@qq.com> Date: Fri, 5 Jul 2024 18:38:40 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=88=98=E6=B4=8B=E7=9A=84=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- soft/datas.py | 32 ++++++++++++++++++++++++++++++++ soft/predict.py | 25 +++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 soft/datas.py create mode 100644 soft/predict.py diff --git a/soft/datas.py b/soft/datas.py new file mode 100644 index 0000000..ea305fa --- /dev/null +++ b/soft/datas.py @@ -0,0 +1,32 @@ +datas={ + "city":"吕梁", + "area":"100", + "rooms":"2", + "school":"1", + "style":"1", + "price":8000, +} +{ + "city":"吕梁", + "area":"100", + "rooms":"2", + "school":"1", + "style":"1", + "price":8000, +} +{ + "city":"太原", + "area":"100", + "rooms":"2", + "school":"1", + "style":"1", + "price":8000, +} +{ + "city":"吕梁", + "area":"200", + "rooms":"2", + "school":"1", + "style":"0", + "price":9000, +} \ No newline at end of file diff --git a/soft/predict.py b/soft/predict.py new file mode 100644 index 0000000..27861f6 --- /dev/null +++ b/soft/predict.py @@ -0,0 +1,25 @@ +import numpy as np +from datas import datas +X=[] +Y=[] +cityMark={"吕梁":1, "太原":2} +for item in datas: + single=[] + single.append(cityMark[item["city"]]) + + single.append(item["area"]) + single.append(item["rooms"]) + single.append(item["school"]) + single.append(item["style"]) + + X.append(single) + Y.append(item["price"]) + +x=np.array(X) +y=np.array(Y) +print(X) +print(y) + +theta=np.linalg.pinv(X.T.dot(X)).dot(X.T).dot(Y) + +print(theta.dot(np.array[2,100,2,1,1])) \ No newline at end of file -- Gitee From 46f78d3f7f5c0b5cba5b3162666a0a3f17bc0105 Mon Sep 17 00:00:00 2001 From: liuy <3454986494@qq.com> Date: Fri, 5 Jul 2024 18:53:29 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=88=98=E6=B4=8B=E7=9A=84=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- soft/__pycache__/datas.cpython-312.pyc | Bin 0 -> 410 bytes soft/datas.py | 15 ++++++++------ soft/predict.py | 26 ++++++++++++++----------- 3 files changed, 24 insertions(+), 17 deletions(-) create mode 100644 soft/__pycache__/datas.cpython-312.pyc diff --git a/soft/__pycache__/datas.cpython-312.pyc b/soft/__pycache__/datas.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e5c6abc359d463a06693595ba94a97eb94fda38a GIT binary patch literal 410 zcmX@j%ge<81Xs_sr+sH+V0aATzyMeV$ocF6B&IW@Fr+Z1Fr_d9AxjGD95xI-8=5>@ z3OiUmM+zrMeL71NLnW6ccPSgtxTh1QK3mjyi`me?;1;9NEk?sk2YChtO}1Ms$(bdU zw^$O3QWI~n7Uk#X7T;nkPR_{B&$-1~TvC~ndW*H7C^I<~V#<L67Ucrzl8pSkfTH}Y)Z`KaqnP6Sw2~OG zYQ2KWUmP~M`6;D2sdhzzK#joQU??sC5+9fu85uutFz|@n;1;;S!+(PpO!5ePexRiQ_nUJs literal 0 HcmV?d00001 diff --git a/soft/datas.py b/soft/datas.py index ea305fa..7f8fcc5 100644 --- a/soft/datas.py +++ b/soft/datas.py @@ -1,11 +1,13 @@ -datas={ +datas=[ + +{ "city":"吕梁", "area":"100", "rooms":"2", "school":"1", "style":"1", "price":8000, -} +}, { "city":"吕梁", "area":"100", @@ -13,7 +15,7 @@ datas={ "school":"1", "style":"1", "price":8000, -} +}, { "city":"太原", "area":"100", @@ -21,12 +23,13 @@ datas={ "school":"1", "style":"1", "price":8000, -} +}, { - "city":"吕梁", + "city":"太原", "area":"200", "rooms":"2", "school":"1", "style":"0", "price":9000, -} \ No newline at end of file +} + ] \ No newline at end of file diff --git a/soft/predict.py b/soft/predict.py index 27861f6..ce59959 100644 --- a/soft/predict.py +++ b/soft/predict.py @@ -1,12 +1,15 @@ import numpy as np from datas import datas -X=[] -Y=[] -cityMark={"吕梁":1, "太原":2} + +X = [] +Y = [] + + +cityMark = {"吕梁": 1, "太原": 2} + for item in datas: - single=[] + single = [] single.append(cityMark[item["city"]]) - single.append(item["area"]) single.append(item["rooms"]) single.append(item["school"]) @@ -15,11 +18,12 @@ for item in datas: X.append(single) Y.append(item["price"]) -x=np.array(X) -y=np.array(Y) +X = np.array(X, dtype=float) +Y = np.array(Y, dtype=float) print(X) -print(y) - -theta=np.linalg.pinv(X.T.dot(X)).dot(X.T).dot(Y) +print(Y) +theta = np.linalg.pinv(X.T.dot(X)).dot(X.T).dot(Y) +print(theta) -print(theta.dot(np.array[2,100,2,1,1])) \ No newline at end of file +prediction = theta.dot(np.array([2, 100, 2, 1, 1])) +print(prediction) -- Gitee