-
Notifications
You must be signed in to change notification settings - Fork 29
/
applylinearmodel.py
executable file
·39 lines (27 loc) · 1.09 KB
/
applylinearmodel.py
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
34
35
36
37
38
#!/usr/bin/env python3
import numpy as np
import pandas as pd
import argparse, sys, pickle
from sklearn.linear_model import *
def rms(x):
return np.sqrt(np.mean(x**2))
def scoremodel(model, x, y):
'''Return fitness of model. We'll use R^2 and RMS.
We also compare to the RMS with the mean.'''
p = model.predict(x).squeeze()
r = rms(p-y)
aver = rms(y-np.mean(y)) #RMS if we just used average
return np.corrcoef(p,y)[0,1]**2,r,aver
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Apply linear model to fingerprint file')
parser.add_argument('model',help='Model file')
parser.add_argument('input',help='Fingerprints input file')
args = parser.parse_args()
comp = 'gzip' if args.input.endswith('.gz') else None
data = pd.read_csv(args.input,compression=comp,header=None,delim_whitespace=True)
x = np.array(data.iloc[:,2:],dtype=np.float)
smi = data.iloc[:,0]
model = pickle.load(open(args.model,'rb'))
p = model.predict(x).squeeze()
for (m, score) in zip(smi,p):
print(m,score)