def get_model(): req_data = request.get_json() dataset_json = req_data['Dataset'] x_axis = req_data['x_axis'] y_axis = req_data['y_axis'] model_name = req_data['Model_name'] model_type = req_data['Model_type'] date = req_data['date'] time = req_data['time'] no_var = req_data['no_var'] if(model_type == "log_regression"): modal_whole, modal_score, c_matrix, keep = m.preprocessing( dataset_json, x_axis, y_axis, model_name, model_type) #c_matrix = pd.Series(c_matrix).to_json() c_matrix = json.dumps(c_matrix) return jsonify({ "Model_name": model_name, "Model_type": model_type, "Model": modal_whole, "Accuracy": modal_score, "c_matrix": c_matrix, "Keep": keep, "date": date, "time": time, "no_var": no_var, "x_axis": x_axis, "y_axis": y_axis }) else: model_pre, model, coeff, xtest = m.preprocessing( dataset_json, x_axis, y_axis, model_name, model_type) coeff = pd.Series(coeff).to_json(orient='values') df_js = model_pre.to_json(orient='records') xtest = xtest.to_json(orient='records') print("coeff:", coeff) print("np_of_var : "+no_var) return jsonify({ "Model_name": model_name, "Coefficient and Intercept": coeff, "Model_type": model_type, "x_axis": x_axis, "y_axis": y_axis, "Model": model, "Dataset": df_js, "X_test": xtest, "date": date, "time": time, "no_var": no_var })
def telemetry(sid, data): global sequence_num # The current steering angle of the car steering_angle = data["steering_angle"] # The current throttle of the car throttle = data["throttle"] # The current speed of the car speed = data["speed"] # The current image from the center camera of the car imgString = data["image"] image = Image.open(BytesIO(base64.b64decode(imgString))) # Uncomment to save the images before feeding them to the NN. Useful for debugging or visualizations #image.save("debug/{0:0>10}.jpg".format(sequence_num)) sequence_num += 1 image_array = preprocessing(np.asarray(image)) image_array = image_array.reshape(np.hstack((1, image_array.shape))) # This model currently assumes that the features of the model are just the images. Feel free to change this. steering_angle = float(model.predict(image_array, batch_size=1)[0]) print("angle: ", steering_angle) # Very basic way to keep a constant speed if float(speed) < desired_speed: throttle = desired_speed / 30. else: throttle = 0.05 #print(steering_angle, throttle) send_control(steering_angle, throttle)
def telemetry(sid, data): if data: # The current steering angle of the car steering_angle = data["steering_angle"] # The current throttle of the car throttle = data["throttle"] # The current speed of the car speed = data["speed"] # The current image from the center camera of the car imgString = data["image"] image = Image.open(BytesIO(base64.b64decode(imgString))) image_array = np.asarray(image) image_array = preprocessing(image_array) steering_angle = float( model.predict(image_array[None, :, :, :], batch_size=1)) throttle = controller.update(float(speed)) print(steering_angle, throttle) send_control(steering_angle, throttle) # save frame if args.image_folder != '': timestamp = datetime.utcnow().strftime('%Y_%m_%d_%H_%M_%S_%f')[:-3] image_filename = os.path.join(args.image_folder, timestamp) image.save('{}.jpg'.format(image_filename)) else: # NOTE: DON'T EDIT THIS. sio.emit('manual', data={}, skip_sid=True)
def complaint_form(): print(url_for('complaint_form')) if request.method == 'POST': # Fetch form data user_details = request.form name = user_details['Name'] email = user_details['Email'] date_today = date.today().strftime("%Y-%m-%d") issue = user_details['Issue'] sub_issue = user_details['Sub-issue'] narrative = user_details['Consumer complaint narrative'] product = model.prediction_category([model.preprocessing(issue, sub_issue, narrative)])[0] cur = mysql.connection.cursor() cur.execute( "INSERT INTO users(Name, Email, `Date received`, Issue, `Sub-issue`, `Consumer complaint narrative`, Product) VALUES(%s,%s,%s,%s,%s,%s,%s)", (name, email, date_today, issue, sub_issue, narrative, product)) mysql.connection.commit() model.send_the_email(recipient='*****@*****.**', subject='A new complaint registered under the category: {}'.format(product), body='Hi, \nHope you are doing well. There has been a new complaint in your category: {}'.format( product) + '\nHave a nice day.\n\nThanks and Regards,\nXXXCRP.') cur.execute( "SELECT * FROM users ORDER BY Id DESC LIMIT 1" ) user_details = cur.fetchall() cur.close() return render_template('thank_you.html', user_details=user_details) return render_template('complaint_form.html')
def train(): data = load_dataset(dataset_path) print('Step1: Dataset is loaded successfully!') preprocessed_data = preprocessing(data) print('Step2: Data preprocessing done successfully!') train, test = train_test_split(preprocessed_data) print('Step3: Data splitted into train and test successfully!') train_X, train_Y, test_X, test_Y, vectorizer = feature_extraction( train, test) trained_model = model_training(train_X, train_Y) print('Step4: Model trained successfully successfully!') accuracy = model_testing(test_X, test_Y, trained_model) vec_classifier = Pipeline([('vectorizer', vectorizer), ('classifier', trained_model)]) save_model(vec_classifier) print('Step5: Model is deployed successfully') response = { 'success': True, 'message': 'Model deployed', 'accuracy': accuracy } return response
def telemetry(sid, data): # The current steering angle of the car steering_angle = data["steering_angle"] # The current throttle of the car throttle = data["throttle"] # The current speed of the car speed = float(data["speed"]) # The current image from the center camera of the car imgString = data["image"] image = Image.open(BytesIO(base64.b64decode(imgString))) image_array = np.asarray(image) # Preprocessing center Image image_array = preprocessing(image_array, input_shape=(64, 64)) transformed_image_array = image_array[None, :, :, :] # This model currently assumes that the features of the model are just the images. Feel free to change this. steering_angle = float(model.predict(transformed_image_array, batch_size=1)) # The driving model currently just outputs a constant throttle. Feel free to edit this. #throttle = 0.2 throttle = (17.0 - speed)*0.5 print(steering_angle, throttle) send_control(steering_angle, throttle)
def telemetry(sid, data): # The current steering angle of the car steering_angle = data["steering_angle"] # The current throttle of the car throttle = data["throttle"] # The current speed of the car speed = data["speed"] # The current image from the center camera of the car imgString = data["image"] image = Image.open(BytesIO(base64.b64decode(imgString))) image_array = np.asarray(image) #image_array = cv2.cvtColor(image_array, cv2.COLOR_BGR2GRAY) image_array = preprocessing(image_array) shape = image_array.shape #image_array = image_array.reshape(shape[0], shape[1], 1) transformed_image_array = image_array[None, :, :, :] # This model currently assumes that the features of the model are just the images. Feel free to change this. steering_angle = float(model.predict(transformed_image_array, batch_size=1)) # The driving model currently just outputs a constant throttle. Feel free to edit this. throttle = 0.2 print(steering_angle, throttle) send_control(steering_angle, throttle)
from model import (load_dataset, preprocessing, train_test_split, model_testing, model_training, load_model, save_model, feature_extraction, predict, append_list_as_row) from sklearn.metrics import accuracy_score import pandas as pd from sklearn.pipeline import Pipeline dataset_path = 'Dataset/Customer_data.csv' try: data = load_dataset(dataset_path) print('Step1: Dataset is loaded successfully!') preprocessed_data = preprocessing(data) print('Step2: Data preprocessing done successfully!') train, test = train_test_split(preprocessed_data) print('Step3: Data splitted into train and test successfully!') train_X, train_Y, test_X, test_Y, vectorizer = feature_extraction( train, test) trained_model = model_training(train_X, train_Y) print('Step4: Model trained successfully successfully!') accuracy = model_testing(test_X, test_Y, trained_model) vec_classifier = Pipeline([('vectorizer', vectorizer), ('classifier', trained_model)]) save_model(vec_classifier)
def predict(): if request.method=='POST': form=request.form age=form['age'] marital=form['marital'] default=form['default'] housing=form['housing'] loan=form['loan'] contact=form['contact'] month=form['month'] day_of_week=form['day_of_week'] duration=form['duration'] campaign=form['campaign'] pdays=form['pdays'] previous=form['previous'] poutcome=form['poutcome'] job=form['job'] education=form['education'] emp_var_rate=1.1 cons_price_idx=93.2 cons_conf_idx=-42.7 euribor3m=4.968 nr_employed=form['employed'] #marital if(marital=='married'): marital_single=0 marital_married=1 marital_divorced=0 marital_unknown=0 elif(marital=='single'): marital_single=1 marital_married=0 marital_divorced=0 marital_unknown=0 elif(marital=='divorced'): marital_single=0 marital_married=0 marital_divorced=1 marital_unknown=0 elif(marital=='unknown'): marital_single=0 marital_married=0 marital_divorced=0 marital_unknown=1 #default if(default=='yes'): default_yes=1 default_no=0 default_unknown=0 elif(default=='no'): default_yes=0 default_no=1 default_unknown=0 else: default_yes=0 default_no=0 default_unknown=1 #housing if(housing=='yes'): housing_yes=1 housing_no=0 housing_unknown=0 elif(housing=='no'): housing_yes=0 housing_no=1 housing_unknown=0 else: housing_yes=0 housing_no=0 housing_unknown=1 #loan if(loan=='yes'): loan_yes=1 loan_no=0 loan_unknown=0 elif(loan=='no'): loan_yes=0 loan_no=1 loan_unknown=0 else: loan_yes=0 loan_no=0 loan_unknown=1 #contact if(contact=='cellular'): contact_cellular=1 contact_telephone=0 else: contact_cellular=0 contact_telephone=1 #job if(job=='admin'): job_admin=1 job_blue_collar=0 job_entrepreneur=0 job_housemaid=0 job_management=0 job_retired=0 job_self_employed=0 job_services=0 job_student=0 job_technician=0 job_unemployed=0 job_unknown=0 elif(job=='blue_collar'): job_admin=0 job_blue_collar=1 job_entrepreneur=0 job_housemaid=0 job_management=0 job_retired=0 job_self_employed=0 job_services=0 job_student=0 job_technician=0 job_unemployed=0 job_unknown=0 elif(job=='entreprenuer'): job_admin=0 job_blue_collar=0 job_entrepreneur=1 job_housemaid=0 job_management=0 job_retired=0 job_self_employed=0 job_services=0 job_student=0 job_technician=0 job_unemployed=0 job_unknown=0 elif(job=='housemaid'): job_admin=0 job_blue_collar=0 job_entrepreneur=0 job_housemaid=1 job_management=0 job_retired=0 job_self_employed=0 job_services=0 job_student=0 job_technician=0 job_unemployed=0 job_unknown=0 elif(job=='management'): job_admin=0 job_blue_collar=0 job_entrepreneur=0 job_housemaid=0 job_management=1 job_retired=0 job_self_employed=0 job_services=0 job_student=0 job_technician=0 job_unemployed=0 job_unknown=0 elif(job=='retired'): job_admin=0 job_blue_collar=0 job_entrepreneur=0 job_housemaid=0 job_management=0 job_retired=1 job_self_employed=0 job_services=0 job_student=0 job_technician=0 job_unemployed=0 job_unknown=0 elif(job=='self_employed'): job_admin=0 job_blue_collar=0 job_entrepreneur=0 job_housemaid=0 job_management=0 job_retired=0 job_self_employed=1 job_services=0 job_student=0 job_technician=0 job_unemployed=0 job_unknown=0 elif(job=='services'): job_admin=0 job_blue_collar=0 job_entrepreneur=0 job_housemaid=0 job_management=0 job_retired=0 job_self_employed=0 job_services=1 job_student=0 job_technician=0 job_unemployed=0 job_unknown=0 elif(job=='student'): job_admin=0 job_blue_collar=0 job_entrepreneur=0 job_housemaid=0 job_management=0 job_retired=0 job_self_employed=0 job_services=0 job_student=1 job_technician=0 job_unemployed=0 job_unknown=0 elif(job=='technician'): job_admin=0 job_blue_collar=0 job_entrepreneur=0 job_housemaid=0 job_management=0 job_retired=0 job_self_employed=0 job_services=0 job_student=0 job_technician=1 job_unemployed=0 job_unknown=0 elif(job=='unemployed'): job_admin=0 job_blue_collar=0 job_entrepreneur=0 job_housemaid=0 job_management=0 job_retired=0 job_self_employed=0 job_services=0 job_student=0 job_technician=0 job_unemployed=1 job_unknown=0 else: job_admin=0 job_blue_collar=0 job_entrepreneur=0 job_housemaid=0 job_management=0 job_retired=0 job_self_employed=0 job_services=0 job_student=0 job_technician=0 job_unemployed=0 job_unknown=1 #education if(education=='basic.4y'): education_basic_4y=1 education_basic_6y=0 education_basic_9y=0 education_high_school=0 education_illiterate=0 education_professional_course=0 education_university_degree=0 education_unknown=0 elif(education=='basic.6y'): education_basic_4y=0 education_basic_6y=1 education_basic_9y=0 education_high_school=0 education_illiterate=0 education_professional_course=0 education_university_degree=0 education_unknown=0 elif(education=='basic.9y'): education_basic_4y=0 education_basic_6y=0 education_basic_9y=1 education_high_school=0 education_illiterate=0 education_professional_course=0 education_university_degree=0 education_unknown=0 elif(education=='high_school'): education_basic_4y=0 education_basic_6y=0 education_basic_9y=0 education_high_school=1 education_illiterate=0 education_professional_course=0 education_university_degree=0 education_unknown=0 elif(education=='illiterate'): education_basic_4y=0 education_basic_6y=0 education_basic_9y=0 education_high_school=0 education_illiterate=1 education_professional_course=0 education_university_degree=0 education_unknown=0 elif(education=='professional_course'): education_basic_4y=0 education_basic_6y=0 education_basic_9y=0 education_high_school=0 education_illiterate=0 education_professional_course=1 education_university_degree=0 education_unknown=0 elif(education=='university_degree'): education_basic_4y=0 education_basic_6y=0 education_basic_9y=0 education_high_school=0 education_illiterate=0 education_professional_course=0 education_university_degree=1 education_unknown=0 else: education_basic_4y=0 education_basic_6y=0 education_basic_9y=0 education_high_school=0 education_illiterate=0 education_professional_course=0 education_university_degree=0 education_unknown=1 #month if(month=='mar'): month_apr=0 month_aug=0 month_dec=0 month_jul=0 month_jun=0 month_mar=1 month_may=0 month_nov=0 month_oct=0 month_sep=0 elif(month=='apr'): month_apr=1 month_aug=0 month_dec=0 month_jul=0 month_jun=0 month_mar=0 month_may=0 month_nov=0 month_oct=0 month_sep=0 elif(month=='may'): month_apr=0 month_aug=0 month_dec=0 month_jul=0 month_jun=0 month_mar=0 month_may=1 month_nov=0 month_oct=0 month_sep=0 elif(month=='jun'): month_apr=0 month_aug=0 month_dec=0 month_jul=0 month_jun=1 month_mar=0 month_may=0 month_nov=0 month_oct=0 month_sep=0 elif(month=='jul'): month_apr=0 month_aug=0 month_dec=0 month_jul=1 month_jun=0 month_mar=0 month_may=0 month_nov=0 month_oct=0 month_sep=0 elif(month=='aug'): month_apr=0 month_aug=1 month_dec=0 month_jul=0 month_jun=0 month_mar=0 month_may=0 month_nov=0 month_oct=0 month_sep=0 elif(month=='sep'): month_apr=0 month_aug=0 month_dec=0 month_jul=0 month_jun=0 month_mar=0 month_may=0 month_nov=0 month_oct=0 month_sep=1 elif(month=='oct'): month_apr=0 month_aug=0 month_dec=0 month_jul=0 month_jun=0 month_mar=0 month_may=0 month_nov=0 month_oct=1 month_sep=0 elif(month=='nov'): month_apr=0 month_aug=0 month_dec=0 month_jul=0 month_jun=0 month_mar=0 month_may=0 month_nov=1 month_oct=0 month_sep=0 #day if(day_of_week== 'mon'): day_of_week_fri=0 day_of_week_mon=1 day_of_week_thu=0 day_of_week_tue=0 day_of_week_wed=0 elif(day_of_week== 'tue'): day_of_week_fri=0 day_of_week_mon=0 day_of_week_thu=0 day_of_week_tue=1 day_of_week_wed=0 elif(day_of_week== 'wed'): day_of_week_fri=0 day_of_week_mon=0 day_of_week_thu=0 day_of_week_tue=0 day_of_week_wed=1 elif(day_of_week== 'thu'): day_of_week_fri=0 day_of_week_mon=0 day_of_week_thu=1 day_of_week_tue=0 day_of_week_wed=0 elif(day_of_week== 'fri'): day_of_week_fri=1 day_of_week_mon=0 day_of_week_thu=0 day_of_week_tue=0 day_of_week_wed=0 #poutcome if(poutcome=='failure'): poutcome_failure=1 poutcome_nonexistent=0 poutcome_success=0 elif(poutcome=='success'): poutcome_failure=0 poutcome_nonexistent=0 poutcome_success=1 elif(poutcome=='nonexistent'): poutcome_failure=0 poutcome_nonexistent=1 poutcome_success=0 datapoint=[[]] datapoint=[np.array([job_admin, job_blue_collar, job_entrepreneur, job_housemaid, job_management, job_retired, job_self_employed, job_services, job_student, job_technician, job_unemployed, job_unknown, marital_divorced, marital_married, marital_single, marital_unknown, education_basic_4y,education_basic_6y, education_basic_9y, education_high_school, education_illiterate, education_professional_course, education_university_degree, education_unknown, default_no, default_unknown, default_yes, housing_no, housing_unknown, housing_yes, loan_no, loan_unknown, loan_yes, contact_cellular, contact_telephone, month_apr, month_aug, month_dec, month_jul, month_jun, month_mar, month_may, month_nov, month_oct, month_sep, day_of_week_fri, day_of_week_mon, day_of_week_thu, day_of_week_tue, day_of_week_wed, poutcome_failure, poutcome_nonexistent, poutcome_success, age, cons_price_idx, cons_conf_idx, campaign, pdays, previous, euribor3m, nr_employed])] scl_obj = MinMaxScaler(feature_range =(0, 1)) scl_obj.fit(datapoint) # find scalings for each column that make this zero mean and unit std X_train_scaled = scl_obj.transform(datapoint) print(X_train_scaled) X_train_scaled=np.array(X_train_scaled) #X_train_scaled.reshape(1,-1).astype('float32') x=X_train_scaled X_train,X_test,y_train,y_test=preprocessing() value = logisticreg(X_train,X_test,y_train,y_test).predict(x) print(value) value1 = int(value[0]) if(value1==1): #return render_template('index.html') return render_template('yes.html') else: return render_template('no.html')
import pandas as pd import model import os df = pd.read_csv('data/alls.csv') df["Content"] = df["Content"].str.lower() df["Content"] = df["Content"].str.replace('[^\w\s]', '') text = " ".join(" ".join(df["Content"].tolist()).split()) print(df.head()) print(text[:200]) model.preprocessing(text) if not os.path.exists("model"): os.mkdir("model") model.feature_build() model.build() lstm_model = model.load() chars = sorted(list(set(text))) text = 'the present study is a history of the dewey' for subtext in range(0, len(text) - 3, 1): now_subtext = text[subtext:subtext + 3] predict = model.predict_completions(lstm_model, now_subtext, chars) print(f"text: {now_subtext}: {predict}") # print(predict)