def crossval(clf=None, X=None, y=None, folds=10, n=5): if X is None or y is None: X, y = get_train_data() clf = clf or get_model() tot = 0 print("KFold folds={}, running {} times".format(folds, n)) for i in range(n): res = cross_val_score(clf, X, y, cv=folds).mean() tot += res print("{}/{}: {}".format(i + 1, n, res)) print("-------- total --------") print(tot / n) return tot / n
def predict_test_data(input_file_path, model_path=None, device=""): lp = get_model(model_path) predictions = [] labels = [] with open(input_file_path) as f: for line in f: data_sample = json.loads(line) predictions.append(lp.predict(data_sample)[0]) labels.append( input_file_path.replace( 't.txt', '').replace('.txt', '').replace( '/home/pi/.whereami/test_data/test_', '').replace( 'C:\\Users\\Daniel\\.whereami\\test_data\\test_', '')) return predictions, labels
def crossval(clf=None, X=None, y=None, folds=10, n=5, path=None): if X is None or y is None: X, y = get_train_data(path) if len(X) < folds: raise ValueError('There are not enough samples ({}). Need at least {}.'.format(len(X), folds)) clf = clf or get_model(path) tot = 0 print("KFold folds={}, running {} times".format(folds, n)) for i in range(n): res = cross_val_score(clf, X, y, cv=folds).mean() tot += res print("{}/{}: {}".format(i + 1, n, res)) print("-------- total --------") print(tot / n) return tot / n
def refresh(self): self.clf = get_model(self.model) self.wifi_scanner = get_scanner(self.device)
def __init__(self, model=None, device=""): self.model = model self.device = device self.clf = get_model(model) self.wifi_scanner = get_scanner(device) self.predicted_value = None
def predictprint(input_path=None, model_path=None, device=""): lp = get_model(model_path) data_sample = sample( device) if input_path is None else get_external_sample(input_path) return json.dumps(dict(zip(lp.classes_, lp.predict_proba(data_sample)[0])))
def predict(input_path=None, model_path=None, device=""): lp = get_model(model_path) data_sample = sample( device) if input_path is None else get_external_sample(input_path) return lp.predict(data_sample)[0]
def predict_proba(): lp = get_model() print({x: y for x, y in zip(lp.classes_, lp.predict_proba(sample())[0])})
def predict(): lp = get_model() return lp.predict(sample())[0]
def predict(): lp = get_model() print(lp.predict(sample())[0])
def crossval(): X, y = get_train_data() lp = get_model() print(cross_validate_model(lp, X, y))