Teery commited on
Commit
06145ba
·
1 Parent(s): 37867a9

first commit

Browse files
Files changed (1) hide show
  1. LogReg.py +78 -0
LogReg.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pandas as pd
3
+ import matplotlib.pyplot as plt
4
+ import seaborn as sns
5
+ import streamlit as st
6
+ from sklearn.preprocessing import StandardScaler
7
+
8
+
9
+ class LogisticRegression():
10
+ def __init__(self, learning_rate =0.01, n_inputs=500):
11
+ self.learning_rate = learning_rate
12
+ self.n_inputs = n_inputs
13
+ self.coef_ = None
14
+ self.intercept_ = None
15
+
16
+ def fit(self, X, y):
17
+ X = np.array(X)
18
+ n_samp, n_feat = X.shape
19
+ self.coef_ = np.zeros(n_feat)
20
+ self.intercept_ = 0
21
+ for _ in range(self.n_inputs):
22
+ lin_pred = [email protected]_ + self.intercept_
23
+ predictions = 1/(1+np.exp(-lin_pred))
24
+
25
+ di = predictions-y
26
+ dc = X * di.reshape(-1, 1)
27
+
28
+ self.coef_ -= self.learning_rate * dc.mean(axis=0)
29
+ self.intercept_ -= self.learning_rate * di.mean()
30
+
31
+ st.title('Выберите файл')
32
+ uploaded_file = st.file_uploader(label='', label_visibility='collapsed', type=["csv"])
33
+ if uploaded_file:
34
+ df = pd.read_csv(uploaded_file).drop('Unnamed: 0', axis=1)
35
+ st.write(df.head(3))
36
+ target = st.selectbox('Выберите столбец, который будет целью обучения', *[df.columns])
37
+ features = st.multiselect('Выберите признаки', *[df.columns])
38
+ if features:
39
+ new_df = df.copy()
40
+ ss = StandardScaler()
41
+ new_df[features] = ss.fit_transform(new_df[features])
42
+
43
+ logreg = LogisticRegression(0.01, 5000)
44
+ logreg.fit(new_df[features], new_df[target].to_numpy())
45
+
46
+ outdict = pd.DataFrame(logreg.coef_.reshape(1,-1), columns=features)
47
+ st. write(outdict)
48
+
49
+ st.write('# Графики :chart_with_upwards_trend:')
50
+ x = st.selectbox("Выберите X", *[df.columns])
51
+ y = st.selectbox('Выберите Y', *[df.columns])
52
+ if x and y:
53
+ choose = st.selectbox('Выберите график', ['Диаграмма рассеяния', 'Столбчатая диаграмма', 'Линейная диаграмма'])
54
+ if choose == 'Диаграмма рассеяния':
55
+ plt.figure(figsize=(20, 15))
56
+ plt.scatter(x=new_df[x], y=new_df[y])
57
+ plt.xlabel(x)
58
+ plt.ylabel(y)
59
+ plt.grid(True)
60
+ st.pyplot(plt)
61
+ elif choose == 'Столбчатая диаграмма':
62
+ plt.figure(figsize=(20, 15))
63
+ plt.bar(x=new_df[x].sort_values(), height=new_df[y].sort_values())
64
+ plt.xlabel(x)
65
+ plt.ylabel(y)
66
+ plt.grid(True)
67
+ st.pyplot(plt)
68
+ elif choose == 'Линейная диаграмма':
69
+ plt.figure(figsize=(20, 15))
70
+ plt.plot(new_df[x].sort_values(), new_df[y].sort_values())
71
+ plt.xlabel(x)
72
+ plt.ylabel(y)
73
+ plt.grid(True)
74
+ st.pyplot(plt)
75
+
76
+
77
+
78
+