Промежуточное.
This commit is contained in:
parent
5fd49b30af
commit
2ab8066933
@ -1,6 +1,6 @@
|
|||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|
||||||
def createDataFrame():
|
def createDataFrame():
|
||||||
df = pd.read_csv('../res/Stores.csv')
|
df = pd.read_csv('res/Stores.csv')
|
||||||
|
|
||||||
return df
|
return df
|
198
LabWork01/LabWork5/create_plot.py
Normal file
198
LabWork01/LabWork5/create_plot.py
Normal file
@ -0,0 +1,198 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import pandas as pd
|
||||||
|
import matplotlib
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import sns
|
||||||
|
from sklearn import metrics
|
||||||
|
from sklearn.model_selection import train_test_split
|
||||||
|
from sklearn.linear_model import LinearRegression
|
||||||
|
|
||||||
|
INCH = 25.4
|
||||||
|
|
||||||
|
def create_plot_jpg(df: pd.DataFrame, nameFile):
|
||||||
|
# для сохранения диаграммы в конкретной папке
|
||||||
|
script_dir = os.path.dirname(__file__)
|
||||||
|
results_dir = os.path.join(script_dir, '../static/')
|
||||||
|
|
||||||
|
if not os.path.isdir(results_dir):
|
||||||
|
os.makedirs(results_dir)
|
||||||
|
|
||||||
|
# набор атрибутов - независимых переменных - площадь
|
||||||
|
_X = df["Store_Area"].array
|
||||||
|
|
||||||
|
# набор меток - зависимых переменных, значение которых требуется предсказать - выручка
|
||||||
|
_Y = df["Store_Sales"].array
|
||||||
|
|
||||||
|
# делим датафрейм на набор тренировочных данных и данных для тестов, test_size содержит определние соотношения этих наборов
|
||||||
|
X_train, X_test, y_train, y_test = train_test_split(_X, _Y, test_size=0.01, random_state=0)
|
||||||
|
|
||||||
|
regressor = LinearRegression()
|
||||||
|
|
||||||
|
X_train = X_train.reshape(-1, 1)
|
||||||
|
X_test = X_test.reshape(-1, 1)
|
||||||
|
|
||||||
|
regressor.fit(X_train, y_train)
|
||||||
|
|
||||||
|
# массив numpy, который содержит все предсказанные значения для входных значений в серии X_test
|
||||||
|
y_pred = regressor.predict(X_test)
|
||||||
|
|
||||||
|
df.plot(x='Store_Sales', y='Store_Area', style='o')
|
||||||
|
|
||||||
|
plt.title('Store sales / Store area')
|
||||||
|
plt.xlabel('Store sales')
|
||||||
|
plt.ylabel('Store area')
|
||||||
|
|
||||||
|
plt.savefig(results_dir + nameFile + '.jpg')
|
||||||
|
plt.close()
|
||||||
|
|
||||||
|
listMessages = ['Mean Absolute Error: ' + str(metrics.mean_absolute_error(y_test, y_pred)),
|
||||||
|
'Mean Squared Error: ' + str(metrics.mean_squared_error(y_test, y_pred)),
|
||||||
|
'Root Mean Squared Error: ' + str(np.sqrt(metrics.mean_squared_error(y_test, y_pred)))]
|
||||||
|
|
||||||
|
return listMessages
|
||||||
|
|
||||||
|
# def graph_regression_plot_sns(
|
||||||
|
# X, Y,
|
||||||
|
# regression_model,
|
||||||
|
# Xmin=None, Xmax=None,
|
||||||
|
# Ymin=None, Ymax=None,
|
||||||
|
# display_residuals=False,
|
||||||
|
# title_figure=None, title_figure_fontsize=None,
|
||||||
|
# title_axes=None, title_axes_fontsize=None,
|
||||||
|
# x_label=None,
|
||||||
|
# y_label=None,
|
||||||
|
# label_fontsize=None, tick_fontsize=12,
|
||||||
|
# label_legend_regr_model='', label_legend_fontsize=12,
|
||||||
|
# s=50, linewidth_regr_model=2,
|
||||||
|
# graph_size=None,
|
||||||
|
# file_name=None):
|
||||||
|
# X = np.array(X)
|
||||||
|
# Y = np.array(Y)
|
||||||
|
# Ycalc = Y - regression_model(X)
|
||||||
|
#
|
||||||
|
# if not (Xmin) and not (Xmax):
|
||||||
|
# Xmin = min(X) * 0.99
|
||||||
|
# Xmax = max(X) * 1.01
|
||||||
|
# if not (Ymin) and not (Ymax):
|
||||||
|
# Ymin = min(Y) * 0.99
|
||||||
|
# Ymax = max(Y) * 1.01
|
||||||
|
#
|
||||||
|
# # график с остатками
|
||||||
|
# # ------------------
|
||||||
|
# if display_residuals:
|
||||||
|
# if not (graph_size):
|
||||||
|
# graph_size = (297 / INCH, 420 / INCH / 1.5)
|
||||||
|
# if not (title_figure_fontsize):
|
||||||
|
# title_figure_fontsize = 18
|
||||||
|
# if not (title_axes_fontsize):
|
||||||
|
# title_axes_fontsize = 16
|
||||||
|
# if not (label_fontsize):
|
||||||
|
# label_fontsize = 13
|
||||||
|
# if not (label_legend_fontsize):
|
||||||
|
# label_legend_fontsize = 12
|
||||||
|
# fig = plt.figure(figsize=graph_size)
|
||||||
|
# fig.suptitle(title_figure, fontsize=title_figure_fontsize)
|
||||||
|
# ax1 = plt.subplot(2, 1, 1)
|
||||||
|
# ax2 = plt.subplot(2, 1, 2)
|
||||||
|
#
|
||||||
|
# # фактические данные
|
||||||
|
# ax1.set_title(title_axes, fontsize=title_axes_fontsize)
|
||||||
|
# sns.scatterplot(
|
||||||
|
# x=X, y=Y,
|
||||||
|
# label='data',
|
||||||
|
# s=s,
|
||||||
|
# color='red',
|
||||||
|
# ax=ax1)
|
||||||
|
# ax1.set_xlim(Xmin, Xmax)
|
||||||
|
# ax1.set_ylim(Ymin, Ymax)
|
||||||
|
# ax1.axvline(x=0, color='k', linewidth=1)
|
||||||
|
# ax1.axhline(y=0, color='k', linewidth=1)
|
||||||
|
# # ax1.set_xlabel(x_label, fontsize = label_fontsize)
|
||||||
|
# ax1.set_ylabel(y_label, fontsize=label_fontsize)
|
||||||
|
# ax1.tick_params(labelsize=tick_fontsize)
|
||||||
|
#
|
||||||
|
# # график регрессионной модели
|
||||||
|
# nx = 100
|
||||||
|
# hx = (Xmax - Xmin) / (nx - 1)
|
||||||
|
# x1 = np.linspace(Xmin, Xmax, nx)
|
||||||
|
# y1 = regression_model(x1)
|
||||||
|
# sns.lineplot(
|
||||||
|
# x=x1, y=y1,
|
||||||
|
# color='blue',
|
||||||
|
# linewidth=linewidth_regr_model,
|
||||||
|
# legend=True,
|
||||||
|
# label=label_legend_regr_model,
|
||||||
|
# ax=ax1)
|
||||||
|
# ax1.legend(prop={'size': label_legend_fontsize})
|
||||||
|
#
|
||||||
|
# # график остатков
|
||||||
|
# ax2.set_title('Residuals', fontsize=title_axes_fontsize)
|
||||||
|
# ax2.set_xlim(Xmin, Xmax)
|
||||||
|
# # ax2.set_ylim(Ymin, Ymax)
|
||||||
|
# sns.scatterplot(
|
||||||
|
# x=X, y=Ycalc,
|
||||||
|
# # label='фактические данные',
|
||||||
|
# s=s,
|
||||||
|
# color='orange',
|
||||||
|
# ax=ax2)
|
||||||
|
#
|
||||||
|
# ax2.axvline(x=0, color='k', linewidth=1)
|
||||||
|
# ax2.axhline(y=0, color='k', linewidth=1)
|
||||||
|
# ax2.set_xlabel(x_label, fontsize=label_fontsize)
|
||||||
|
# ax2.set_ylabel(r'$ΔY = Y - Y_{calc}$', fontsize=label_fontsize)
|
||||||
|
# ax2.tick_params(labelsize=tick_fontsize)
|
||||||
|
#
|
||||||
|
# # график без остатков
|
||||||
|
# # -------------------
|
||||||
|
# else:
|
||||||
|
# if not (graph_size):
|
||||||
|
# graph_size = (297 / INCH, 210 / INCH)
|
||||||
|
# if not (title_figure_fontsize):
|
||||||
|
# title_figure_fontsize = 18
|
||||||
|
# if not (title_axes_fontsize):
|
||||||
|
# title_axes_fontsize = 16
|
||||||
|
# if not (label_fontsize):
|
||||||
|
# label_fontsize = 14
|
||||||
|
# if not (label_legend_fontsize):
|
||||||
|
# label_legend_fontsize = 12
|
||||||
|
# fig, axes = plt.subplots(figsize=graph_size)
|
||||||
|
# fig.suptitle(title_figure, fontsize=title_figure_fontsize)
|
||||||
|
# axes.set_title(title_axes, fontsize=title_axes_fontsize)
|
||||||
|
#
|
||||||
|
# # фактические данные
|
||||||
|
# sns.scatterplot(
|
||||||
|
# x=X, y=Y,
|
||||||
|
# label='фактические данные',
|
||||||
|
# s=s,
|
||||||
|
# color='red',
|
||||||
|
# ax=axes)
|
||||||
|
#
|
||||||
|
# # график регрессионной модели
|
||||||
|
# nx = 100
|
||||||
|
# hx = (Xmax - Xmin) / (nx - 1)
|
||||||
|
# x1 = np.linspace(Xmin, Xmax, nx)
|
||||||
|
# y1 = regression_model(x1)
|
||||||
|
# sns.lineplot(
|
||||||
|
# x=x1, y=y1,
|
||||||
|
# color='blue',
|
||||||
|
# linewidth=linewidth_regr_model,
|
||||||
|
# legend=True,
|
||||||
|
# label=label_legend_regr_model,
|
||||||
|
# ax=axes)
|
||||||
|
#
|
||||||
|
# axes.set_xlim(Xmin, Xmax)
|
||||||
|
# axes.set_ylim(Ymin, Ymax)
|
||||||
|
# axes.axvline(x=0, color='k', linewidth=1)
|
||||||
|
# axes.axhline(y=0, color='k', linewidth=1)
|
||||||
|
# axes.set_xlabel(x_label, fontsize=label_fontsize)
|
||||||
|
# axes.set_ylabel(y_label, fontsize=label_fontsize)
|
||||||
|
# axes.tick_params(labelsize=tick_fontsize)
|
||||||
|
# axes.legend(prop={'size': label_legend_fontsize})
|
||||||
|
#
|
||||||
|
# plt.show()
|
||||||
|
# if file_name:
|
||||||
|
# fig.savefig(file_name, orientation="portrait", dpi=300)
|
||||||
|
#
|
||||||
|
# return
|
@ -13,6 +13,7 @@ from LabWork01.LabWork3.CreateGraphics import createGraphics
|
|||||||
from LabWork01.LabWork3.CustomGraphics import createCusGraphics
|
from LabWork01.LabWork3.CustomGraphics import createCusGraphics
|
||||||
from LabWork01.LabWork3.DeletePng import deleteAllPng
|
from LabWork01.LabWork3.DeletePng import deleteAllPng
|
||||||
from LabWork01.LabWork4.SiteSearch import SiteSearch
|
from LabWork01.LabWork4.SiteSearch import SiteSearch
|
||||||
|
from LabWork01.LabWork5.create_plot import create_plot_jpg
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
@ -45,7 +46,7 @@ search_engine.add("https://www.kaggle.com/datasets/fedesoriano/stroke-prediction
|
|||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def home():
|
def home():
|
||||||
return render_template('main_page.html', context=[], main_img=[], image_names=[], tableAnalys=[], titles=[''], listTypes=listTypes, countNull=countNull, firstRow=1, secondRow=4, firstColumn=1, secondColumn=4)
|
return render_template('main_page.html', context=[], main_img=[], messages=[], image_names=[], tableAnalys=[], titles=[''], listTypes=listTypes, countNull=countNull, firstRow=1, secondRow=4, firstColumn=1, secondColumn=4)
|
||||||
|
|
||||||
@app.route("/showDiapason", methods=['GET','POST'])
|
@app.route("/showDiapason", methods=['GET','POST'])
|
||||||
def numtext():
|
def numtext():
|
||||||
@ -83,7 +84,7 @@ def numtext():
|
|||||||
totalList.append(listStoreSales)
|
totalList.append(listStoreSales)
|
||||||
|
|
||||||
if int(data['firstRow']) and int(data['secondRow']) and int(data['firstColumn']) and int(data['secondColumn']):
|
if int(data['firstRow']) and int(data['secondRow']) and int(data['firstColumn']) and int(data['secondColumn']):
|
||||||
return render_template('main_page.html', context=totalList, main_img=[], image_names=[], listTypes=listTypes, countNull=countNull,
|
return render_template('main_page.html', context=totalList, main_img=[], messages=[], image_names=[], listTypes=listTypes, countNull=countNull,
|
||||||
firstColumn=int(data['firstColumn']), secondColumn=int(data['secondColumn']),
|
firstColumn=int(data['firstColumn']), secondColumn=int(data['secondColumn']),
|
||||||
firstRow=int(data['firstRow']), secondRow=int(data['secondRow']))
|
firstRow=int(data['firstRow']), secondRow=int(data['secondRow']))
|
||||||
|
|
||||||
@ -157,6 +158,7 @@ def analysis():
|
|||||||
tableAnalysThree=[],
|
tableAnalysThree=[],
|
||||||
tableAnalysFour=[],
|
tableAnalysFour=[],
|
||||||
main_img=newCustomJpg,
|
main_img=newCustomJpg,
|
||||||
|
messages=[],
|
||||||
titles=[''],
|
titles=[''],
|
||||||
listTypes=listTypes, countNull=countNull, firstRow=1,
|
listTypes=listTypes, countNull=countNull, firstRow=1,
|
||||||
secondRow=4, firstColumn=1, secondColumn=4)
|
secondRow=4, firstColumn=1, secondColumn=4)
|
||||||
@ -184,6 +186,32 @@ def get_page_showFindURL():
|
|||||||
|
|
||||||
return render_template('showLinks.html', links=links)
|
return render_template('showLinks.html', links=links)
|
||||||
|
|
||||||
|
# 5-я лабораторная
|
||||||
|
@app.route('/createPlotImage', methods=['GET', 'POST'])
|
||||||
|
def get_plot_image():
|
||||||
|
|
||||||
|
# 99%
|
||||||
|
# main_df = listShops.loc[listShops['Store_ID'] <= listShops.shape[0]*0.9]
|
||||||
|
|
||||||
|
# 1%
|
||||||
|
# support_df = listShops.loc[listShops['Store_ID'] > listShops.shape[0]*0.9]
|
||||||
|
|
||||||
|
messages = create_plot_jpg(listShops, "myPlot")
|
||||||
|
|
||||||
|
myPlotJpg = ['myPlot.jpg']
|
||||||
|
|
||||||
|
return render_template('main_page.html', context=[], image_names_start=[],
|
||||||
|
image_names_addition=[],
|
||||||
|
tableAnalysOne=[],
|
||||||
|
tableAnalysTwo=[],
|
||||||
|
tableAnalysThree=[],
|
||||||
|
tableAnalysFour=[],
|
||||||
|
main_img=myPlotJpg,
|
||||||
|
messages=messages,
|
||||||
|
titles=[''],
|
||||||
|
listTypes=listTypes, countNull=countNull, firstRow=1,
|
||||||
|
secondRow=4, firstColumn=1, secondColumn=4)
|
||||||
|
|
||||||
if __name__=="__main__":
|
if __name__=="__main__":
|
||||||
app.run(debug=True)
|
app.run(debug=True)
|
||||||
|
|
||||||
|
@ -23,6 +23,9 @@
|
|||||||
<form action='http://127.0.0.1:5000/analysis' method=get>
|
<form action='http://127.0.0.1:5000/analysis' method=get>
|
||||||
<input type=submit value='Анализ данных'>
|
<input type=submit value='Анализ данных'>
|
||||||
</form>
|
</form>
|
||||||
|
<form action='/createPlotImage' method=get>
|
||||||
|
<input type=submit value='Создание регрессии'>
|
||||||
|
</form>
|
||||||
<form action="/findURL" method="get">
|
<form action="/findURL" method="get">
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<button type="submit" class="btn btn-primary mb-3">Запуск фильтра</button>
|
<button type="submit" class="btn btn-primary mb-3">Запуск фильтра</button>
|
||||||
@ -79,6 +82,11 @@
|
|||||||
</h3>
|
</h3>
|
||||||
{% for image_name in main_img %}
|
{% for image_name in main_img %}
|
||||||
<img src="{{ url_for('static', filename=image_name) }}" alt="{{ image_name }}">
|
<img src="{{ url_for('static', filename=image_name) }}" alt="{{ image_name }}">
|
||||||
|
{% for message in messages %}
|
||||||
|
<div>
|
||||||
|
<p>{{message}}</p>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
|
Loading…
Reference in New Issue
Block a user