-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathUseExistingClassifier.py
More file actions
34 lines (28 loc) · 1.27 KB
/
UseExistingClassifier.py
File metadata and controls
34 lines (28 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import pickle
import numpy as np
import pandas as pd
import subprocess
outputoverlappath = "/tudelft.net/staff-umbrella/haplotype/2018/data/potato/Solanum_tuberosum.SolTub_3.0.dna_sm.chromosome.4.fa-chr-4-ploidy1-cov-30-72208621-"
base_name = "results/4-features-30-72208621-"
features_name = ['Centrality', 'Degree', 'Node2Vec', 'ShortestPath', 'SLL']
def classifyoverlaps(base_name, modelpath, threshold):
threshold = 1 - threshold
X_test = list()
for feature in features_name:
if feature == 'Node2Vec':
n2v = pd.read_csv(base_name + '-' + feature, delimiter=',', header=None)
n2v = n2v.values
for i in range(len(n2v[0])):
X_test.append(n2v[:, i])
else:
X_test.append(pd.read_csv(base_name + '-' + feature, delimiter=',', header=None).values.flatten())
X_test = np.asarray(X_test).T
print(np.shape(X_test))
clf = pickle.load(open(modelpath, 'rb'))
scaler = pickle.load(open('models/scaler-potato', 'rb'))
X_test = scaler.transform(X_test)
Y_test_pred_prob = clf.predict_proba(X_test)
Y_test_pred_prob = np.asarray(Y_test_pred_prob)[:, 1]
Y_test_pred_prob[Y_test_pred_prob > threshold] = 1
Y_test_pred_prob[Y_test_pred_prob < threshold] = 0
return Y_test_pred_prob