Skip to content

Commit 51b6131

Browse files
authored
Merge pull request #6 from JEENB/models
models, models, pdf, user_dir implemented
2 parents f939539 + 13000f7 commit 51b6131

36 files changed

+781
-177
lines changed
4.67 KB
Binary file not shown.

__pycache__/models.cpython-39.pyc

1.68 KB
Binary file not shown.

__pycache__/utils.cpython-39.pyc

433 Bytes
Binary file not shown.

app.py

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
import dearpygui.dearpygui as dpg
2+
import os
3+
4+
5+
#client code starts#
6+
import os
7+
import socket
8+
import time
9+
10+
11+
PORT = 2223
12+
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
13+
client.connect((socket.gethostname(), PORT))
14+
print("[INFO] Connected to server")
15+
#client code ends#
16+
17+
18+
19+
20+
def login_callback(sender, app_data, user_data):
21+
22+
print("Save Clicked")
23+
print(f"sender is {sender}")
24+
print(f"app_data is {app_data}")
25+
print(f"user data is {user_data}")
26+
print(dpg.get_value("username"))
27+
print(dpg.get_value("password"))
28+
dpg.delete_item("original")
29+
30+
with dpg.window(label="Example Window", width=500, height=500, tag="original"):
31+
dpg.add_text("you have logged in")
32+
with dpg.file_dialog(directory_selector=False, show=False, callback=choose_file_callback, id="file_dialog_id"):
33+
dpg.add_file_extension(".csv")
34+
# dpg.add_file_extension("", color=(150, 255, 150, 255))
35+
# dpg.add_file_extension("Source files (*.cpp *.h *.hpp){.cpp,.h,.hpp}", color=(0, 255, 255, 255))
36+
# dpg.add_file_extension(".h", color=(255, 0, 255, 255), custom_text="[header]")
37+
# dpg.add_file_extension(".py", color=(0, 255, 0, 255), custom_text="[Python]")
38+
dpg.add_button(label="File Selector", callback=lambda: dpg.show_item("file_dialog_id"))
39+
40+
41+
42+
43+
def choose_file_callback(sender, app_data):
44+
print(f"Sender: {sender}")
45+
print(f"App Data: {app_data}")
46+
file_name = app_data["file_name"]
47+
file_path = app_data["file_path_name"]
48+
print(file_name)
49+
50+
#============client code starts===========#
51+
file_size = os.path.getsize(file_path)
52+
print(file_size)
53+
print("[INFO] sending file size")
54+
client.send(str(file_size).encode())
55+
56+
57+
# Opening file and sending data.
58+
with open(file_name, "rb") as file:
59+
c = 0
60+
# Starting the time capture.
61+
start_time = time.time()
62+
63+
# Running loop while c != file_size.
64+
while c <= file_size:
65+
data = file.read(1024)
66+
if not (data):
67+
break
68+
client.sendall(data)
69+
c += len(data)
70+
71+
# Ending the time capture.
72+
end_time = time.time()
73+
74+
print("[INFO] File Transfer Complete.Total time: ", end_time - start_time)
75+
#============client code ends==========#
76+
dpg.delete_item("original")
77+
with dpg.window(label="Example Window", width=500, height=500, tag="original"):
78+
dpg.add_text("Your file has been selected and sent to server.")
79+
dpg.add_text("Enter the desired degree of your regression model. Eg-3")
80+
dpg.add_input_text(label="Regression Degree", tag="model_degree")
81+
dpg.add_text("Slide to choose the desired percentage of dataset for testing. Rest will be used for training")
82+
dpg.add_slider_int(label="Testing percentage", tag="model_test_percentage")
83+
dpg.add_button(label="Send to server", callback=send_model_data)
84+
85+
86+
def send_model_data():
87+
model_degree = dpg.get_value("model_degree")
88+
model_test_percentage = str(dpg.get_value("model_test_percentage"))
89+
print(dpg.get_value("model_degree"))
90+
print(dpg.get_value("model_test_percentage"))
91+
#======client code starts=====
92+
client.send(model_degree.encode())
93+
client.send(model_test_percentage.encode())
94+
#========client code ends=======
95+
96+
97+
dpg.delete_item("original")
98+
with dpg.window(label="Example Window", width=500, height=500, tag="original"):
99+
dpg.add_text("Data sent to server")
100+
dpg.add_text("Model is getting trained by the model.....")
101+
102+
103+
def get_model_inputs():
104+
pass
105+
106+
107+
108+
109+
110+
111+
112+
113+
114+
115+
116+
117+
118+
119+
120+
121+
122+
123+
dpg.create_context()
124+
dpg.create_viewport(title="Machine Learning on Server", width=500, height=500)
125+
dpg.setup_dearpygui()
126+
127+
128+
129+
130+
131+
with dpg.window(label="Example Window", width=500, height=500, tag="original"):
132+
dpg.add_text("Enter your login credentials")
133+
dpg.add_input_text(label="User Name", tag="username")
134+
dpg.add_input_text(label="Password", tag="password")
135+
dpg.add_button(label="Login", callback=login_callback)
136+
# dpg.add_slider_float(label="float")
137+
138+
139+
140+
141+
142+
dpg.show_viewport()
143+
dpg.start_dearpygui()
144+
dpg.destroy_context()
145+
146+

client.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

client1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
88
client.connect((socket.gethostname(), PORT))
99
print("[INFO] Connected to server")
10-
file_name = "original.jpeg"
10+
file_name = "dataset.csv"
1111
file_size = os.path.getsize(file_name)
1212

13-
print("[INFO] sending file")
13+
print("[INFO] sending file size")
1414
client.send(str(file_size).encode())
1515

1616

create_report.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
from fpdf import FPDF
2+
from datetime import datetime
3+
4+
5+
6+
7+
8+
pdf = FPDF()
9+
10+
def section(string, pdf=pdf):
11+
pdf.set_font('Courier','B', 14)
12+
pdf.cell(0,7,string, ln = 2)
13+
14+
def line(string, pdf= pdf):
15+
pdf.set_font('Courier', '', 11)
16+
pdf.cell(0,5,string, ln = 2)
17+
18+
def multi_line(string, pdf=pdf):
19+
pdf.set_font('Courier', '', 11)
20+
pdf.multi_cell(0,5, string)
21+
22+
def c_report(tot, maxi, mini, mean, medi, sd, training_points, testing_points, degree, split, user_dir):
23+
file_name = "report.pdf"
24+
width = 210
25+
height = 297
26+
pdf.set_margins(15,15)
27+
pdf.set_title('Regression Report')
28+
pdf.set_font('Helvetica', '', 14)
29+
30+
pdf.add_page()
31+
pdf.image("./report/1.png",0,0,width)
32+
pdf.write(20, f"Prepared by:")
33+
pdf.ln(1.5)
34+
pdf.set_font('Courier', '', 11)
35+
pdf.write(27,"Server.py")
36+
37+
pdf.add_page()
38+
pdf.set_font('Courier', 'B', 20)
39+
pdf.cell(0,20,"Regression Report", ln = 2, align="C", border='B')
40+
41+
line("")
42+
section("User Defined Parameters")
43+
line(f"Dataset: received.txt")
44+
line(f"Polynomial Degree = {degree}")
45+
line(f"Train-test-split = {split}%")
46+
line("")
47+
48+
section("Dataset Exploration")
49+
line(f"Total Points = {tot}")
50+
line(f"Training Points = {training_points}")
51+
line(f"Testing Points = {testing_points}")
52+
line(f"Max = {maxi}")
53+
line(f"Min = {mini}")
54+
line(f"Mean = {mean}")
55+
line(f"Median = {medi}")
56+
line(f"Standard Deviation = {sd}")
57+
line("")
58+
59+
section("Results")
60+
61+
section("1. Polynomial Fitting")
62+
pdf.image(f"{user_dir}/fitting.png",50,140,w=120, h = 72)
63+
pdf.ln(84)
64+
multi_line("The above figure represents the regression line being fitted to the training instances. If the regression line passes through all the points then the polynomial degree chosen overfits the data. Similarly, if the line does not touch even a single point, you might be underfitting the training instances.")
65+
66+
pdf.add_page()
67+
section("2. Actual vs Predicted")
68+
pdf.image(f"{user_dir}/actual_pred.png",50,20,w=120, h = 72)
69+
pdf.ln(84)
70+
multi_line("The above scatter plot represents the spread of predicted and actual scores. Assuming out model perfectly fits the data we can expect the points spread across the y = x line.")
71+
line("")
72+
73+
74+
section("3. Residual vs Predicted")
75+
pdf.image(f"{user_dir}/actual_pred.png",50,140,w=120, h = 72)
76+
pdf.ln(84)
77+
line("Residual = h(x) - f(x)")
78+
line("where,")
79+
line("h(x) is the predicted value and f(x) is the actual value")
80+
line("")
81+
multi_line("The fitted vs residuals plot is mainly useful for investigating: Whether linearity holds. This is indicated by the mean residual value for every fitted value region being close to 0. In R this is indicated by the red line being close to the dashed line. Whether homoskedasticity holds. The spread of residuals should be approximately the same across the x-axis. Whether there are outliers. This is indicated by some extreme residuals that are far from the rest.")
82+
83+
84+
pdf.add_page()
85+
section("4. Mean Squared Error")
86+
pdf.image(f"{user_dir}/compare_error.png",50,20,w=120, h = 72)
87+
pdf.ln(80)
88+
multi_line("The mean squared error is calculated as the sum of differences in actual and predicted result squared. The lower the MSE the better the model performs.")
89+
line("")
90+
91+
section("4. Normal Q-Q Plots")
92+
pdf.image(f"{user_dir}/normalqq.png",50,125,w=120, h = 72)
93+
pdf.ln(75)
94+
line("")
95+
multi_line("The Q-Q plot, or quantile-quantile plot, is a graphical tool to help us assess if a set of data plausibly came from some theoretical distribution such as a Normal or exponential. For example, if we run a statistical analysis that assumes our dependent variable is Normally distributed, we can use a Normal Q-Q plot to check that assumption. It's just a visual check, not an air-tight proof, so it is somewhat subjective. But it allows us to see at-a-glance if our assumption is plausible, and if not, how the assumption is violated and what data points contribute to the violation.")
96+
line('')
97+
multi_line("A Q-Q plot is a scatterplot created by plotting two sets of quantiles against one another. If both sets of quantiles came from the same distribution, we should see the points forming a line that's roughly straight. Here's an example of a Normal Q-Q plot when both sets of quantiles truly come from Normal distributions.")
98+
99+
pdf.add_page()
100+
pdf.image("./report/2.png",0,0,width)
101+
102+
pdf.output(f"{user_dir}/report.pdf", 'F')
103+
return 0
104+

dataset.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,4 @@ x,y
9999
50.039575939875988,85.232007342325673
100100
48.149858891028863,66.224957888054632
101101
25.128484647772304,53.454394214850524
102+
22.23, 21.23

0 commit comments

Comments
 (0)