def testLinearSVC(self): ml = ML() t = Training("classification", "LinearSVC", { "maxIter": 10, "regParam": 0.3 }, 0.7, sample_libsvm_data, "./model/svc") ml.train_model(t)
def register_ml(self, ml): """Register a new ML object in flow""" self.clfs[ml.meta['name']] = ML(classifier=ml.clf, name=ml.meta['name']) return self
def test_init(self): ml = ML() assert hasattr(ml, 'clf') assert ml.clf is None assert ml.meta == {'name': ''}
def testMultilayerPerceptronClassifier(self): # TODO param layers is neccesary ml = ML() t = Training("classification", "MultilayerPerceptronClassifier", {"layers": [4, 5, 4, 3]}, 0.7, sample_multiclass_classification_data, "./model/mlp") print(ml.train_model(t))
def main(): """ Main function. """ warnings.filterwarnings("ignore") # get data from csv file, and catch error reading file try: df = pd.read_csv('data/dataset_mood_smartphone.csv', sep=",") except OSError as e: print("ERROR: cannot open or read input file") # get command line options args = get_args() df = util.init_data(df) # initial model if args.prediction_models == "ml": model = ML() elif args.prediction_models == "temporal_algorithm": model = Temporal() elif args.prediction_models == "benchmark": model = Benchmark() else: sys.exit("BUG! this should not happen.") # call pipline predictions, evaluation_scores = model.pipeline(df) # print output util.output_to_file(predictions, args.pred_file) # util.output_to_file(evaluation_scores, args.eval_file) util.output_to_screen(evaluation_scores)
def testLibsvm(self): s = Source("../data/test.data", "csv", json.dumps({ "header": True, "delimiter": "," }), {}) ml = ML() df = ml.read_source(s) print(df.schema.json())
def testLogisticRegression(self): ml = ML() t = Training( "classification", "LogisticRegression", { "maxIter": 10, "regParam": 0.3, "elasticNetParam": 0.8, "family": "multinomial" }, 0.7, iris, "./model/lr") ml.train_model(t)
def __init__(self, port, row_list, voltage, current, power, cumpower): self.port = port self.row_list = row_list self.columns = ['ax1', 'ay1', 'az1', 'gx1', 'gy1', 'gz1','ax2', 'ay2', 'az2', 'gx2', 'gy2', 'gz2'] self.df = pd.DataFrame(columns = self.columns) self.counter = 0 self.voltage = voltage self.current = current self.power = power self.cumpower = cumpower self.model = ML()
def __init__(self,values,all_data,**kwargs): self.period = kwargs.get('period', 0.005) self.start_time = values['time'] self.previous_time = values['time'] self.previous_be = values['be'] self.duration = kwargs.get('duration', float('inf')) self.previous_vel = values['av'] sys.path.insert(0, "../../Machine_Learning") from ml import ML self.ml = ML("../../Machine_Learning/winner.pkl")
def testCSV(self): ml = ML() # ml.compute_statistics(iris, "sepallength") t = Training( "classification", "LogisticRegression", { "maxIter": 10, "regParam": 0.3, "elasticNetParam": 0.8, "family": "multinomial" }, 0.7, iris, "./model/lr") # ml.train_model(t) ml.model_predict_single(t, iris)
def _process(programs): ml = ML(programs) f = open("features.csv", "r") out = open("featuresml.txt", "w") next(f) for linha in f: data = linha.strip("\n") id = linha.split(",")[0] res = ml.prediction(data.split(",")) out.write(str(id) + "," + str(res) + "\n") out.close() f.close()
def testJDBC(self): s = Source( "", "jdbc", json.dumps({ "url": "jdbc:mysql://10.110.17.222/insight_ml", "driver": "com.mysql.jdbc.Driver", "dbtable": "user_info", "user": "******", "password": "" }), {}) ml = ML() df = ml.read_source(s) ml.compute_statistics(s, "user_name") print(df.schema.json())
def __init__(self, max_features=5000, test=False, feature_stratergy="Tfidf"): self.info = Information() self.preprocess = Preprocess() self.make_features = make_features(test) self.ml = ML() self.resue = test if self.resue: self.vectorizer = pickle.load( open("vectorizers/vectorizer.pkl", "rb")) print("INFERENCE PHASE") else: print("TRAINING PHASE") if feature_stratergy == "Tfidf": self.vectorizer = TfidfVectorizer(max_features=max_features) elif feature_stratergy == "Count": self.vectorizer = CountVectorizer(max_features=max_features)
def build(self): main_box = BoxLayout() painter_size = '500dp' draw_parent = BoxLayout(orientation='vertical', size_hint_x = None, width = painter_size ) labels_box = BoxLayout(orientation='vertical') main_box.add_widget(draw_parent) main_box.add_widget(labels_box) self.painter = MyPaintWidget(self.update_res, size_hint_y = None, height = painter_size ) clearbtn = Button(text='Clear') clearbtn.bind(on_release=self.clear_canvas) draw_parent.add_widget(self.painter) draw_parent.add_widget(clearbtn) # addbtn = Button(text='add') # addbtn.bind(on_release=self.add_ev) # labels_box.add_widget(addbtn) w_nums = [] for i in range(10): n_w = NumRes(i) w_nums.append(NumRes(i)) labels_box.add_widget(n_w) self.w_nums = w_nums self.labels_box = labels_box self.machine = ML((28*28, 16, 16, 10, )) self.machine.load_weight('weights_m.out') return main_box
def server(): ml = ML() # Create a TCP/IP socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) # Bind the socket to the port server_address = ('localhost', 10002) log.debug('Inicializando %s na porta %s', server_address[0], server_address[1]) sock.bind(server_address) # Listen for incoming connections sock.listen(1) while True: # Wait for a connection log.debug('Esperando por uma conexao...') connection, client_address = sock.accept() try: log.debug('Conexao de %s', client_address) # Recebendo dados data = connection.recv(2048) data = data.strip("\n") log.debug('\tRecebido %s', data) if data == "EXIT": break; #print '\tRecebido %s' % data res = ml.prediction(data.split(",")) # Enviando dados connection.sendall(str(res) + "\n") log.debug("\tEnviado: %s", res) finally: connection.close() sock.close()
def testRandomForestClassifier(self): ml = ML() t = Training("classification", "RandomForestClassifier", {"maxDepth": 10}, 0.7, sample_libsvm_data, "./model/rf") print(ml.train_model(t))
def testALS(self): ml = ML() t = Training("recommendation", "ALS", {"maxIter": 9}, 0.7, test, "./model/als") ml.model_predict_single() print(ml.train_model(t))
import numpy as np import pandas as pd import matplotlib.pyplot as plt import mplleaflet import IPython from db_psql import DBPsql from ml import ML app = Flask(__name__) bootstrap = Bootstrap(app) db_psql = DBPsql() db_psql.connect() ml = ML(db_psql) # ml.close_db_connection() @app.route('/') def index(): return render_template('index.html') def load_model(db): try: query = """ SELECT clf FROM Model WHERE id = 1 """ db_psql.cursor.execute(query) clf_obj = db_psql.cursor.fetchone()[0] return pickle.loads(clf_obj) except Exception as e: print(e)
def testGeneralizedLinearRegression(self): ml = ML() t = Training("regression", "GeneralizedLinearRegression", {"regParam": 0.3}, 0.7, sample_linear_regression_data, "./model/glr") print(ml.train_model(t))
def testAFTSurvivalRegression(self): # TODO not have test data ml = ML() t = Training("regression", "AFTSurvivalRegression", {}, 0.7, sample_libsvm_data, "./model/aftsr") print(ml.train_model(t))
def testGBTRegressor(self): ml = ML() t = Training("regression", "GBTRegressor", {"maxDepth": 6}, 0.7, sample_libsvm_data, "./model/gbtr") print(ml.train_model(t))
def testRandomForestRegressor(self): ml = ML() t = Training("regression", "RandomForestRegressor", {"maxDepth": 5}, 0.7, sample_libsvm_data, "./model/rfr") print(ml.train_model(t))
def testDecisionTreeRegressor(self): ml = ML() t = Training("regression", "DecisionTreeRegressor", {}, 0.7, sample_libsvm_data, "./model/dtr") print(ml.train_model(t))
def testIsotonicRegression(self): ml = ML() t = Training("regression", "IsotonicRegression", {}, 0.7, sample_linear_regression_data, "./model/isotonic") print(ml.train_model(t))
print(np.around(mtx, decimals=2)) #%% for i in range(20): plt.imshow(test_data[i][0].reshape(( 28, 28, ))) #%% from ml import ML b_machine = ML(( 28 * 28, 16, 16, 10, )) b_machine.load_weight('weights.out') # b_machine.save_weight('weights.out') #%% train_len = 5000 test_len = 10000 if train_len > 10000 else train_len machine = b_machine.copy() machine.load_weight('weights_m.out') machine.train(train_data[:train_len], 80) # machine.save_weight('weights_m.out') print()
def testGBTClassifier(self): ml = ML() t = Training("classification", "GBTClassifier", {"maxDepth": 10}, 0.7, sample_libsvm_data, "./model/gbt") print(ml.train_model(t))
def testNaiveBayes(self): ml = ML() t = Training("classification", "NaiveBayes", {"smoothing": 2.0}, 0.7, sample_libsvm_data, "./model/bayes") print(ml.train_model(t))
def submit(self): harmfull = ['Stroke', 'Cancer', 'Heart Disease', 'Diabetes', 'Tumor'] import sqlite3 conn = sqlite3.connect('proj.db') self.name1 = self.Text1.get('1.0', tk.END) self.age1 = self.Text2.get('1.0', tk.END) self.email1 = self.Text3.get('1.0', tk.END) self.d_year1 = self.Text4.get('1.0', tk.END) self.dropdown1 = self.TCombobox1.get() for i in harmfull: if i == self.dropdown1: self.d_type = 'Deadly' break else: self.d_type = 'Not deadly' if len(self.name1) == 0 or len(self.age1) == 0 or len(self.email1) == 0 or len(self.d_year1) == 0 or len(self.dropdown1) == 0 or self.dropdown1 == 'Choose': import tkinter.messagebox tkinter.messagebox.showinfo('Warning', 'Please fill all the boxes') elif len(self.name1) != 0 and len(self.age1) != 0 and len(self.email1) != 0 and len(self.d_year1) != 0 and len(self.dropdown1) != 0 and self.dropdown1 != 'Choose': c = conn.cursor() c.execute("INSERT INTO hospital VALUES(?,?,?,?,?,?)", (self.name1, self.age1, self.dropdown1, self.email1, self.d_year1, self.d_type,)) c.execute("SELECT age,d_year,disease FROM hospital WHERE name=(?)", [self.name1]) list1 = [] for i in c.fetchall(): list1.append(i) conn.commit() conn.close() # with open("data.csv", "r") as f: # cw = csv.reader(f, delimiter = ' ') # for line in cw: # if line[0]==self.name1: # print(', '.join(line)) # break if list1[0][2] == 'Stroke': t=2 elif list1[0][2] == 'Cancer': t = 3 elif list1[0][2] == 'Heart Disease': t = 4 elif list1[0][2] == 'Malaria': t = 5 elif list1[0][2] == 'Diabetes': t = 6 elif list1[0][2] == 'Tumor': t = 7 elif list1[0][2] == 'Asthma': t = 8 elif list1[0][2] == 'Diarrhea': t = 9 elif list1[0][2] == 'Depression': t = 10 elif list1[0][2] == 'Flu': t = 11 else: t=0 a = list1[0][0] y = list1[0][1] t1 = t obj = ML() pred,accuracy = obj.preprocess(a, y, t1) print("Accuracy =",accuracy) import tkinter.messagebox if pred==0: tkinter.messagebox.showinfo('Thank You', 'We are sorry , Disease is DEADLY but Thank you for your response') self.cancel() elif pred==1: tkinter.messagebox.showinfo('Thank You', 'Disease is NOT DEADLY and Thank you for your response') self.cancel()
def testOneVsRest(self): # TODO param classifier is neccesary ml = ML() t = Training("classification", "OneVsRest", {"maxIter": 10}, 0.7, sample_multiclass_classification_data, "./model/ovr") print(ml.train_model(t))
def testLinearRegression(self): ml = ML() t = Training("regression", "LinearRegression", {"maxIter": 99}, 0.7, sample_linear_regression_data, "./model/linear") print(ml.train_model(t))