添加数据

This commit is contained in:
2019-05-07 16:21:04 +08:00
parent fd45b6921d
commit 906e0afa66
5 changed files with 18500 additions and 35 deletions
File diff suppressed because it is too large Load Diff
+2 -22
View File
@@ -1,23 +1,3 @@
room,total_price
1,7000
1,8500
1,7500
1,6600
2,14000
2,14000
2,12000
2,8200
2,8200
2,14000
2,12000
2,7500
2,8500
2,12000
2,10500
2,8200
2,8000
2,8500
3,14900
3,12000
3,20000
3,12000
1,3000
2,10000
1 room total_price
2 1 7000 3000
3 1 2 8500 10000
1 7500
1 6600
2 14000
2 14000
2 12000
2 8200
2 8200
2 14000
2 12000
2 7500
2 8500
2 12000
2 10500
2 8200
2 8000
2 8500
3 14900
3 12000
3 20000
3 12000
+5 -9
View File
@@ -1,15 +1,12 @@
import os
import sys
import numpy as np
import pandas as pd
from sklearn import preprocessing
from sklearn import svm
from sklearn.model_selection import GridSearchCV, train_test_split
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import PolynomialFeatures
import os
import sys
curPath = os.path.abspath(os.path.dirname(__file__))
rootPath = os.path.split(curPath)[0]
sys.path.append(rootPath)
sys.path.append("/home/wenyan/Sklearn")
import common
@@ -32,11 +29,10 @@ c_range = np.logspace(-5, 15, 11, base=2)
gamma_range = np.logspace(-9, 3, 13, base=2)
param_grid = [{'svr__kernel': ['rbf', 'linear'], 'svr__C': c_range, 'svr__gamma': gamma_range}]
svr = svm.SVR()
pipeline = Pipeline([('poly', PolynomialFeatures(3)),
('standard', preprocessing.StandardScaler()),
pipeline = Pipeline([('standard', preprocessing.StandardScaler()),
('minMax', preprocessing.MinMaxScaler()),
('svr', svr)])
grid = GridSearchCV(pipeline, param_grid, cv=3, n_jobs=10)
grid = GridSearchCV(pipeline, param_grid, cv=3, n_jobs=20)
clf = grid.fit(x_train, y_train.values.ravel())
test_score = grid.score(x_test, y_test)
print('测试得分是%s' % test_score)
+35
View File
@@ -0,0 +1,35 @@
import sys
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeRegressor
from sklearn.pipeline import Pipeline
from sklearn import preprocessing
sys.path.append("/home/wenyan/Sklearn")
import common
base_year = common.parse_date("1900-01-01")
def years(now):
year = common.parse_date(str(now), '%Y')
return int((year - base_year).days/365)
train_data = pd.read_csv(open('../data/小区租金样本.csv'))
train_data["build_year"] = train_data["build_year"].apply(lambda param: years(param))
x = train_data[["lat", "lng", "build_year", "room", "avg_price"]]
y = train_data[["rent_price"]]
x = x.astype(np.float64)
y = y.astype(np.float64)
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=.3)
for depth in range(2, 100):
pipeline = Pipeline([('standard', preprocessing.StandardScaler()),
('minMax', preprocessing.MinMaxScaler()),
('svr', DecisionTreeRegressor(max_depth=depth, max_features =5))])
clf = pipeline.fit(x_train, y_train.values.ravel())
test_score = pipeline.score(x_test, y_test)
print('depth:' + str(depth) + '\t测试得分是%s' % test_score)
print('depth:' + str(depth) + '\t训练得分是%s' % pipeline.score(x_train, y_train))
+3 -3
View File
@@ -243,7 +243,7 @@ def calc_seaweed_rent(seaweed, year_month):
def main():
pool = multiprocessing.Pool(processes=30)
start_date = common.parse_date("2019-05-01")
start_date = common.parse_date("2019-03-01")
now_date = common.localize(datetime.datetime.utcnow())
while start_date < now_date:
year_month = int(common.format_date(start_date - relativedelta(months=1), '%Y%m'))
@@ -257,5 +257,5 @@ def main():
if __name__ == "__main__":
calc_seaweed_rent(common.get_seaweed("北京", "西城", "富国里")[0], 201904)
# main()
#calc_seaweed_rent(common.get_seaweed("北京", "西城", "富国里")[0], 201904)
main()