I am getting this error
ModuleNotFoundError: No module named 'tests'
This is a common error but I don't know what have don't wrong.
This is how my file hierarchy is:
backend
|
'----> __init__.py
'----> server.py
tests
|
'----> __init__.py
'----> linearregression.py
I am calling predict
function in linearregression.py
from server.py
This is my linearregression.py
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn import linear_model
def predict():
.
.
.
return_this = []
return_this.append(price_is)
return_this.append(gradient_is)
return_this.append(intercept_is)
return_this.append(str(predicted_value))
return return_this
if __name__ == '__main__':
returned_values = predict()
price_is = returned_values[0]
gradient_is = returned_values[1]
intercept_is = returned_values[2]
predicted_value = returned_values[3]
and here is my server.py
from flask import Flask
app = Flask(__name__)
from tests.linear_regression.linearregression import predict //importing predict function here
PORT = 8083
returned_values = predict()
price_is = returned_values[0]
gradient_is = returned_values[1]
intercept_is = returned_values[2]
predicted_value = returned_values[3]
def price():
return price_is
def gradient():
return gradient_is
def intercept():
return intercept_is
def predicted_value():
return predicted_value
@app.route('/')
def hello_world():
name = price()
gradient = gradient()
intercept = intercept()
predicted_value = predicted_value()()
return "<h1>Price is: </h1><p>"+price+"</p><br><h1>Gradient is: </h1><p>"+gradient+"</p><br><h1>Intercept is: </h1><p>"+intercept+"</p><br><h1>Predicted value is: </h1><p>"+predicted_value+"</p>"
@app.route('/banuka')
def hi():
return "Hi Jananath"
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8083)
I am using python3.6
Can someone help me what have I done wrong?
Did you installed the "scikit-learn" library correctly?
If not them install it by using pip by running pip install scikit-learn
.
And this should resolve the error.
If still throws an error, then try to reinstall it, by first uninstalling by running pip uninstall scikit-learn
and then installing it again, by pip install scikit-learn
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.