'added_python_code'

parent 7ca73c42
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment