-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
96 lines (88 loc) · 3 KB
/
server.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from flask import Flask, request, jsonify
import joblib
import pandas as pd
import pickle
import numpy as np
import re
import ast
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn import model_selection
from sklearn.model_selection import train_test_split
from sklearn.feature_selection import SelectKBest, f_classif, f_regression
from sklearn import preprocessing
from sklearn.preprocessing import LabelEncoder
from sklearn import linear_model
from sklearn.linear_model import LinearRegression
from sklearn.tree import DecisionTreeRegressor
from sklearn.ensemble import RandomForestRegressor
from sklearn.ensemble import GradientBoostingRegressor
from sklearn.metrics import median_absolute_error
import optuna
from sklearn import ensemble
from sklearn import metrics
from sklearn.linear_model import Ridge
from sklearn.preprocessing import MinMaxScaler
from sklearn.metrics import mean_squared_error
from sklearn.model_selection import GridSearchCV
from sklearn.model_selection import cross_val_score
from sklearn.preprocessing import StandardScaler
from sklearn.decomposition import PCA
from sklearn.linear_model import Lasso
from sklearn.metrics import r2_score
import xgboost as xgb
import time
from sklearn.pipeline import Pipeline
from sklearn.base import BaseEstimator, TransformerMixin
import joblib
from transformers import (
StatusTransformer,
StreetTransformer,
PropertyTypeTransformer,
BathsTransformer,
CityStateTransformer,
HomeFactsTransformer,
CustomFeaturesTransformer,
SchoolsTransformer,
LotSizeSqftTransformer,
ZipcodeTransformer,
BedsTransformer,
StoriesTransformer,
CombinedMlsIDTransformer,
PoolTransformer,
YearBuiltTransformer,
RemodeledYearTransformer,
LotSizeTransformer,
PricePerSqftTransformer,
AvrDistanceTransformer,
MinDistanceTransformer,
AverageRatingTransformer,
CategoricalEncoder,
MlsIDFireplaceTransformer,
FeatureDropper
)
app = Flask(__name__)
# Загрузка pipeline и модели
pipeline = joblib.load('pipeline.pkl')
model = joblib.load('model.pkl')
@app.route('/')
def index():
return "Привет! Это мой веб-сервис для прогнозирования стоимости недвижимости."
@app.route('/upload', methods=['POST'])
def upload_file():
# Получение файла из запроса
uploaded_file = request.files['file']
if uploaded_file:
# Чтение данных из CSV-файла в DataFrame
df = pd.read_csv(uploaded_file)
# Обработка данных с помощью pipeline и модели
pipeline.fit(df)
processed_data = pipeline.transform(df)
predictions = model.predict(processed_data)
predictions = np.exp(predictions)
# Отправка результата
return jsonify(predictions.tolist())
else:
return jsonify({'error': 'Нет файла в запросе'}), 400
if __name__ == '__main__':
app.run('localhost', 5001)