Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
20_21-J09
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
20_21-J09
20_21-J09
Commits
8f81a81d
Commit
8f81a81d
authored
Jul 08, 2021
by
IT17176798_Bhagya Dilhara
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
'added_python_code'
parent
7ca73c42
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
0 deletions
+72
-0
app.py
app.py
+72
-0
No files found.
app.py
0 → 100644
View file @
8f81a81d
from
flask
import
Flask
,
jsonify
,
request
from
textblob
import
TextBlob
import
pandas
as
pd
import
mysql.connector
from
flask_cors
import
CORS
import
matplotlib.pyplot
as
plt
app
=
Flask
(
__name__
)
CORS
(
app
)
@
app
.
route
(
'/prediction/<s_id>'
,
methods
=
[
'GET'
])
def
get
(
s_id
):
mydb
=
mysql
.
connector
.
connect
(
host
=
"localhost"
,
user
=
"root"
,
password
=
"root"
,
database
=
"inteljr"
)
student_id
=
s_id
mycursor
=
mydb
.
cursor
()
sql
=
"""SELECT duration, marks FROM tbl_result_summary WHERE student_id = '
%
s' order by added_date desc"""
%
(
s_id
)
mycursor
.
execute
(
sql
)
myresult
=
mycursor
.
fetchall
()
df
=
pd
.
DataFrame
(
myresult
)
df
.
shape
df
.
head
()
df
.
describe
()
df
=
pd
.
read_sql_query
(
sql
,
mydb
)
df
.
plot
(
x
=
'duration'
,
y
=
'marks'
,
style
=
'*'
)
plt
.
title
(
'Student Mark Prediction'
)
plt
.
xlabel
(
'Hours'
)
plt
.
ylabel
(
'Marks'
)
#plt.show()
x
=
df
.
iloc
[:,
:
-
1
]
.
values
y
=
df
.
iloc
[:,
1
]
.
values
#Split the data into train and test dataset
from
sklearn.model_selection
import
train_test_split
x_train
,
x_test
,
y_train
,
y_test
=
train_test_split
(
x
,
y
,
test_size
=
0.5
,
random_state
=
0
)
#Fitting Simple Linear regression data model to train data set
from
sklearn.linear_model
import
LinearRegression
regressorObject
=
LinearRegression
()
pd
.
plotting
.
register_matplotlib_converters
()
regressorObject
.
fit
(
x_train
,
y_train
)
#predict the test set
y_pred_test_data
=
regressorObject
.
predict
(
x_test
)
y_pred_train_data
=
regressorObject
.
predict
(
x_train
)
# Visualising the Training set results in a scatter plot
plt
.
scatter
(
x_train
,
y_train
,
color
=
'red'
)
plt
.
plot
(
x_train
,
regressorObject
.
predict
(
x_train
),
color
=
'blue'
)
plt
.
xlabel
(
'Duration '
)
plt
.
ylabel
(
'Marks'
)
#plt.show()
print
(
regressorObject
.
intercept_
)
print
(
regressorObject
.
coef_
)
df
=
pd
.
DataFrame
({
'actual'
:
y_pred_train_data
,
'predicted'
:
y_pred_test_data
},
columns
=
[
'actual'
,
'predicted'
])
return
df
.
to_json
(
orient
=
'records'
)
if
__name__
==
"__main__"
:
app
.
run
(
debug
=
True
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment