一、引言
二、背景知识
三、知识运用
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
# -*- coding: utf-8 -*
import
numpy as np
import
os
import
matplotlib.pyplot as plt
def
drawScatterDiagram(fileName):
#改变工作路径到数据文件存放的地方
os.chdir(
"d:/workspace_ml"
)
xcord
=
[];ycord
=
[]
fr
=
open
(fileName)
for
line
in
fr.readlines():
lineArr
=
line.strip().split()
xcord.append(
float
(lineArr[
1
]));ycord.append(
float
(lineArr[
2
]))
plt.scatter(xcord,ycord,s
=
30
,c
=
'red'
,marker
=
's'
)
plt.show()
|
1
|
# -*- coding: utf-8 -*importnumpy as npimportosimportmatplotlib.pyplot as pltdefdrawScatterDiagram(fileName):#改变工作路径到数据文件存放的地方os.chdir("d:/workspace_ml")xcord=[];ycord=[]fr=open(fileName)forline infr.readlines():lineArr=line.strip().split()xcord.append(float(lineArr[1]));ycord.append(float(lineArr[2]))plt.scatter(xcord,ycord,s=30,c='red',marker='s')#a=0.1965;b=-14.486a=0.1612;b=-8.6394x=np.arange(90.0,250.0,0.1)y=a*x+bplt.plot(x,y)plt.show()
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# -*- coding: utf-8 -*
import
numpy as np
import
os
import
matplotlib.pyplot as plt
def
drawScatterDiagram(fileName):
#改变工作路径到数据文件存放的地方
os.chdir(
"d:/workspace_ml"
)
xcord
=
[];ycord
=
[]
fr
=
open
(fileName)
for
line
in
fr.readlines():
lineArr
=
line.strip().split()
xcord.append(
float
(lineArr[
1
]));ycord.append(
float
(lineArr[
2
]))
plt.scatter(xcord,ycord,s
=
30
,c
=
'red'
,marker
=
's'
)
#a=0.1965;b=-14.486
a
=
0.1612
;b
=
-
8.6394
x
=
np.arange(
90.0
,
250.0
,
0.1
)
y
=
a
*
x
+
b
plt.plot(x,y)
plt.show()
|