-
Notifications
You must be signed in to change notification settings - Fork 2
/
uvToOrder.py
46 lines (38 loc) · 953 Bytes
/
uvToOrder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/python
# -*- coding: utf-8 -*-
import numpy as np
from sklearn.linear_model import LinearRegression
import matplotlib.pyplot as plt
from itertools import islice
import csv
# 使用一元线性预测流量和订单的关系
uvCount = []
orderCount = []
price = []
f = open('resource/learn/activityInfo.csv', 'rb')
lines = islice(csv.reader(f), 1, None)
for row in lines:
uvCount.append(int(row[1]))
orderCount.append(int(row[2]))
price.append(int(row[3]))
uvCount = np.array(uvCount)
orderCount = np.array(orderCount)
price = np.array(price)
print uvCount
print orderCount
print price
# uv与订单关系
model = LinearRegression()
x = np.vstack([uvCount]).T
model.fit(x, orderCount)
plt.figure()
## plt.subplot(221)
plt.title('uv and order')
plt.scatter(x, orderCount, color='red')
plt.plot(x, model.predict(x), color='blue')
plt.xticks(())
plt.yticks(())
plt.axis('tight')
plt.xlabel('uv')
plt.ylabel('order')
plt.show()